2

i 'am building a blog website ,where the user can comment with an image ,so for that i'am trying to upload a local image and save it into database (postgres)
for that i used URL.createObjectURL to create a url blob for the image and i save that url to database , and i was thinking that the lifetime of the url unlimited but i was wrong because when i refresh the page an error appears net::ERR_FILE_NOT_FOUND it says that the url not found in the database ,so how i can let the url always available , or if this way not good show me the good practice.

Salah
  • 513
  • 7
  • 18
  • Don't save images to a database. Save the image to a URL-accessible file system (your own data store, AWS, what have you), and store the _location_ of where you put that file in your database (probably with some metadata like original filename, width, height, extension, etc) so you never need to transmit the image as part of your site serving. Let the client's browser be responsible for pulling the image urls. – Mike 'Pomax' Kamermans May 25 '20 at 19:59
  • @ Mike 'Pomax' Kamermans can you give a link for that because i'am confusing and thank you – Salah May 25 '20 at 20:17
  • https://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay - don't store entire blobs in your db. Save those blobs to real files, and put those files somewhere where they can be hosted (e.g. your own server's static directory, an AWS bucket, etc. etc.). Then you store the URL for that image file in your database, and now you don't need to transfer _entire images_ out of your DB when you query it, instead you just get nice and tiny URLs that you can put in your page source, so you're not sending webpages with _entire images_ embedded, but with normal `` code. – Mike 'Pomax' Kamermans May 25 '20 at 20:40
  • 1
    @Mike thank you a lot appreciate ur help. – Salah May 25 '20 at 20:54

0 Answers0