Accept Images from IOS and Andriod in node.js -
how accept images come ios , android in node.js have used multer
module accept multiple images html page in succesfully able images , in below format
fieldname : field name specified in form originalname : name of file on user’s computer encoding : encoding type of file mimetype : mime type of file size : size of file in bytes destination : folder file has been saved filename : name of file within destination path : full path uploaded file buffer : buffer of entire file
so in format ios , andriod should mean in format have send can accept images in node.js , want images inside body along 10 images there json object,below format want accept.
{ "generalinformatio":{ "name":"raj", "image":[ image1 image2 ] }, "deviceinformatio":{ "devicename":"wifi", "image":[ image1 image2 image2 ] } }
below code acceptig jso data
app.post('/adduser',function(req,res){ var mongodbs = require('mongodb'); var parsedresponse = json.parse(json.stringify(req.body)); console.log("startig from"+parsedresponse); mongodb.findbyobjects("userdetails",{generalinformation:{installationid:req.body.generalinformation.installationid}},function(err,deviceresult){ if(err) { res.send({"status":0,"message":"error in retriving record"}); } else { if(deviceresult.length>0) { res.send({"status":0,"message":"this device registered please register device id"}); } else { // mongodb.insertimage('userdetails',req,function(err,result){ // if(err) res.send({"status":0,"message":"error in insertion of record"}); // else{ var parsedresponse = json.parse(json.stringify(req.body)); console.log("da previous class"+parsedresponse); var bodydetails = deviceinformation.getdata(parsedresponse,function(err,data) { console.log('asdfasdfasdfsdf'); }); mongodb.save('userdetails',bodydetails,function(err,resultss){ if (err) { res.send({"status":0,"message":"error in insertion of record"}); } else { res.json(resultss); } }); // } // }); } } }); }); below code accessing image array
var calls = []; var mongodbs = require('mongodb'); req.foreach(function (files){ calls.push(function(callback){ var bucket = new mongodbs.gridfsbucket(state.db, { chunksizebytes: 1024, contenttype:files.mimetype, bucketname: 'usersimage' }); fs.createreadstream(files.image.path).pipe( bucket.openuploadstream(files.image.originalname)).on('error', function(error) { return callback(error); // console.log('error:-', error); }).on('finish', function(saveddata) { var parsedresponse = json.parse(json.stringify(saveddata)); console.log('parsedresponse'); callback(null,parsedresponse._id); fs.unlink(files.image.path, function() { if (err) throw err; logger.info('file uploaded to: ' + files.image.path + ' - ' + files.image.size + ' bytes'); }); }); }); }) async.parallel(calls, function(err, result) { /* code run after calls finished job or when of calls passes error */ if (err) return console.log(err); logger.info(result); callback(null,result); });
when send image html able post image when send json object ios getting error file undefined
there no above format how accept images ios , android?
Comments
Post a Comment