I have written my image upload API in Node.js
, which is working fine in Postman but I'm not getting any way to do that in android. I have tried this library
but still couldn't solve this.My upload image API goes like this
var upload = multer({ dest: '/tmp/'});
app.post('/file_upload', upload.single('file'), function(req, res) {
var file = 'images' + '/' + req.file.filename+'.jpg';
fs.rename(req.file.path, file, function(err) {
if (err) {
console.log(err);
res.send(500);
} else {
res.json({
message: 'File uploaded successfully',
filename: req.file.filename
});
}
});
});
and the Ion library implementation is as follows
Ion.with(this)
.load("http://104.131.162.126:3001/file_upload")
.setMultipartParameter("name", "source")
.setMultipartFile("image", "image/jpeg", f)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject> () {
@Override
public void onCompleted(Exception e, JsonObject result) {
//do stuff with result
dialog.dismiss ();
Toast.makeText (NewActivity.this,"Image uploaded",Toast.LENGTH_LONG).show ();
}
});