1

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 ();

                        }
                    });
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Neha
  • 389
  • 4
  • 8
  • 24
  • Anyone else visiting here: my issue was that i used setBodyParameter instead of setMultipartParameter and changed from JsonObject to String response. . . so check your code there must be some tiny mistake. . – Adam May 17 '19 at 07:12

0 Answers0