Home > database >  Heroku unable to find images in production
Heroku unable to find images in production

Time:01-13

I am using multer to upload upload and saves images in client/images/post folder.

Here is a code snippet:

const storage = multer.diskStorage({
    destination: './client/images/post',
    filename: function(req, file, cb){
    cb(null,file.fieldname   '-'   Date.now()   path.extname(file.originalname));
    }
  });

This works perfect in development. However, when I deploy this node app to heroku, images that are newly uploaded during production can't be found by Heroku.

I get this error:

https://mywebsite/images/post/photo-1673474603560.png 404 (Not Found)

However, if I look at source of other image tags that already existed when deployed - they are able to get into the folder and load their images.

Any ideas?

CodePudding user response:

I believe Heroku uses an ephemeral filesystem. Please refer https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem

Because of this any file/files that is created on the Heroku Dyno is not permanent. You would most likely have to go with other storage solutions if you want proper persistent file storage. While the current setup you have may work for local development, you would have to go for something like S3 in the deployed environment.

  • Related