Sunday, 16 April 2017

Invalid image file http error code 400

controller.js

module.exports.submitMobilePhoto= function(req,res)
{
    var imageBuff= new Buffer(req.body.imageData, 'base64');
    console.log('imageBuff is '+ imageBuff);
    fs.writeFile('./tmp/picture.jpg',imageBuff,function(err){
        if(err)
        {
            console.log('Error Found',err);
        }
        else
        {
            var fileName= process.env.GLOBAL_PATH+'/tmp/picture.jpg';
            console.log('this is fileName', fileName);
            cloudinary.uploader.upload(fileName,function(response)
            {
                console.log(response);
                var picture=new Pic();
                picture.name= req.body.name;
                picture.description=req.body.description;
                picture.url=response.secure_url;
                console.log("This is picture url "+ picture.url);
                picture.save();
                res.status(200).end();
                console.log('This the response '+ res);
            },{
                  "resource_type": "auto"
            });
        }
    })
}

Here i'm getting error of invalid image file and also the path of image is undefined

picture.url=response.secure_url;

I've tried all possible solutions for this but nothing changed



via Asad Arshad

No comments:

Post a Comment