I try the api using the postman and it is ok. the problem is when I try to fetch the image file to be displayed in the front, it becomes invalid image. Do everything but not show the image
function App() { const [singleFile, setSingleFile] = useState([]); const [multipleFile, setMultipleFile] = useState([]); const getSingleFile = async () => { try { const {data} = await axios.get("users/getSingleFile"); return data; } catch (error) { throw error; } } const getSingleFileList = async () => { try { const filelist = await getSingleFile(); setSingleFile(filelist); } catch (error) { console.log(error); } } useEffect(() => { getSingleFileList(); }, []); return ( <div> <div> <Fotos getSingle={() => getSingleFileList} /> </div> {singleFile.map((file, index)=> <img src={ "http://localhost:5000/${file.filePath}"} alt="img"/> )} </div> ) }; export default App;
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Change this, replace ” by “:
<img src={ `http://localhost:5000/${file.filePath}`} alt="img"/>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0