upload a file using express js

Im trying to upload a file using express js. when it runs in local in work correctly. but when i try using fly io it doesnt run correctly. (req.file) shows false and runs with false condition.

const path =require(‘path’)
const multer =require(‘multer’)

var storage =multer.diskStorage({
destination:(req,file,cb)=>{
cb(null,__dirname+“SellerUploads/”)
},
filename: (req,file,cb)=>{
let ext = path.extname(file.originalname);
cb(null,Date.now()+ ext)
}
})

var upload =multer({
storage:storage,
fileFilter:(req,file,callback)=>{
if(file.mimetype == “image/png” || file.mimetype ==“image/jpg”){
callback(null,true);
}else{
console.log(“Image upload error”)
callback(null,false);
}
},
limits:{ fileSize: 102410242}
})

module.exports = upload;

Check your logs for errors; my guess is that you don’t have write permissions to that folder.
Also, you should consider using S3 or R2 presigned url to offload your bandwidth to the client.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.