multer icon indicating copy to clipboard operation
multer copied to clipboard

multer cannot handle images uploaded to cpanel hosting , the request is pending

Open maheshbasnet089 opened this issue 1 year ago • 4 comments

i was unable to post images to cpanel, it works on local machine but not on hosting ,

maheshbasnet089 avatar Apr 12 '23 05:04 maheshbasnet089

Need more information about the situation. Code?

joeyguerra avatar Apr 01 '24 22:04 joeyguerra

//Here is the code for this issue,, working totally fine on local buton cpanel, it waits for photo upload but timeout at end

//.....app /express /cors code

const multer = require("multer") // app.use(cors()); app.use((req, res, next) => { res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Credentials", "true"); res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT,DELETE"); res.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"); next(); })

app.use('/uploads',express.static("./uploads")) // image config var imgconfig =multer.diskStorage({ destination:(req,file,callback)=>{ callback(null,"uploads/") }, filename:(req,file,callback)=>{ callback(null,image-${Date.now()}.${file.originalname}) } }) // image filter const isimage = (req,file,callback)=>{ if(file.mimetype.startsWith("image")){ callback(null,true) } else{ callback(null,Error("Only images are allowed!")) } }

//image upload var upload =multer ({ storage :imgconfig, limits: {fileSize:'2000000'}, fileFilter:isimage })

///....other routes

app.post('/student',upload.single("photo"), (req, res) => {

console.log(req.body)
const {data} = req.body;
const {filename} = req.file

if(!filename || !data){
    res.status(422).json({status:   422,message:"fill all the details!"})
}

try{
    db.query(`insert into student (instituteid,studname,rollno,enrollno,class,section,
                father_name,mother_name,blood_group,dob,address,pincode,gender,contactno,pic) 
                values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
                [...JSON.parse(data),filename],
                  (err, results, fields) => {
            if (err) {
                return console.log(err)
            }
            else{
                res.status(201).json({status:201,message:"Successfully submitted!!!",data : results })
            }
        })
}catch(e){
    res.status(422).json({status: 422,e})
}

})

image

shubhanshusahu avatar Apr 21 '24 14:04 shubhanshusahu

I would change the return console.log(err) code to res.status(500) and see if that's what holding up the response.

joeyguerra avatar Apr 22 '24 19:04 joeyguerra

It was the problem with hosting provider thank you anyway

On Tue, 23 Apr 2024 at 1:19 AM Joey Guerra @.***> wrote:

I would change the return console.log(err) code to res.status(500) and see if that's what holding up the response.

— Reply to this email directly, view it on GitHub https://github.com/expressjs/multer/issues/1200#issuecomment-2070776688, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQXRZ3XDVZXELS6NSMBSXVTY6VQ4BAVCNFSM6AAAAAAW3FFGD2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZQG43TMNRYHA . You are receiving this because you authored the thread.Message ID: @.***>

maheshbasnet089 avatar Apr 22 '24 19:04 maheshbasnet089