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 src 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.