I've read all the answers but still can't wrap my head around what's wrong. I'm trying to display images from MongoDB at react, i can display the path but can't use it. Locallhost is running on port 8080.
The db object looks like this:
{"_id":{"$oid":"614cb6cb8b4b8b3bb8ac7342"},"fileName":"black-sandals-shoes.jpg","filePath":"addedItems\\2021-09-23T17-18-03.302Z-black-sandals-shoes.jpg","fileType":"image/jpeg","fileSize":"104.69-KB","type":"shoes","productType":"shoes","createdAt":{"$date":"2021-09-23T17:18:03.313Z"},"updatedAt":{"$date":"2021-09-23T17:18:03.313Z"},"__v":0}
At server.mjs (addedItems is the folder which stores the images at server side)
app.use('/api/addedItems', express.static(path.join(__dirname, 'addedItems')));
Item component:
export default function Item({ id, filePath, type, productType }) {
return (
<div className="item">
{`http://localhost:8080/${filePath}`}
<img
src={`http://locallhost:8080${filePath}`}
className="item-image"
alt="item-img"
/>
{/*<span>{type}</span>*/}
<span>{productType}</span>
<button>Delete from closet</button>
</div>
);
}
And that's what I get :
http://locallhost:8080/addedItems\2021-09-23T17-18-03.302Z-black-sandals-shoes.jpgitem-img
shoes
Delete from closet
Help me if you can :))