s683
s683

Reputation: 55

store image locally and refrence them in react app

I'm building a desktop app with React and MySQL, I only store the image name in MySQL and the actual images are in the images folder in /src/images, When uploading new images to the images folder, the react app reload, So to avoid that from happening

  1. I either need to store the images in MySQL DB

  2. access the images locally not in /src but outside like D:/images/*.

but react has some importing restrictions.

How can I resolve this issue, please share your knowledge.

Upvotes: 0

Views: 1728

Answers (1)

macborowy
macborowy

Reputation: 1534

You need to import and use images directly in the component or serve your images as publically available static assets.

You can do this in plenty of ways:

  1. Put all images in React's /public/images directory making them static assets of your page
  2. Serve images as static assets from your backend (here how to do it in express.js)
  3. Serve images as static assets from 3rd party storage service (e.g.: Azure Blob Storage)
  4. Store images in database and provide them to frontend as data blobs - while it is possible, it's not recommended.

Upvotes: 2

Related Questions