0

I Am trying to store images on Heroku server ./public.uploades folder but when I try to get images I get 404 not found is there any way to store images in Heroku other AWS s3

const storage = multer.diskStorage({
    destination:function(req,file,cb){
        cb(null,"./public/uploades")     //storage confg
   },
    filename: function (req, file, callback) {
        callback(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
      }

})

const upload = multer({ storage:storage,limits: { fileSize: 5000000 }});

app.get("/fetchimage/", (req, res) => {
    const file = req.query.file
    const fileLocation = path.join('/public/uploades', file);
    res.sendFile(__dirname +fileLocation)
    })
Gurpyar
  • 27
  • 5
  • S3 is the solution here. You can't store uploads on Heroku's servers; they get reset daily and on every deployment. – ceejayoz Mar 23 '22 at 14:14
  • Does this answer your question? [Why do uploaded pictures disappear on Heroku?](https://stackoverflow.com/questions/16210486/why-do-uploaded-pictures-disappear-on-heroku) – ceejayoz Mar 23 '22 at 14:15

1 Answers1

0

Heroku dose not allow any file excluding git. However you can use https://cloudinary.com for image upload its free.

Anik Biswas
  • 120
  • 1
  • 1
  • 7