I am trying to send a bitmap (image captured in camera - Android) to nodejs. I am using AsycnHttpClient for the same. I am able to successfully send query parameters. I did refer to some of the links where the files are being sent and received. I tried the same, however, I guess nodejs code needs to be different for a bitmap and file (not sure?!)
Please can you help?
Client side code:
private void storeImage(Bitmap bm){
AsyncHttpClient client = new AsyncHttpClient();
//Append the parameters in the Service URL
RequestParams rp = new RequestParams();
String SERVICE_URL_REG = SERVICE_URL + "uploadImage?userID=rhari008";
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
ByteArrayInputStream bInput = new ByteArrayInputStream(data);
rp.put("image",bInput);
client.post(SERVICE_URL_REG, rp, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
Log.d(TAG,"Successfully uploaded the image");
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
Log.d(TAG,"Error in uploading the image");
}
});
}
Server side code to receive the parameter:
//Image upload
router.post('/uploadImage', function(req, res, next) {
console.log("Image upload reached for " + req.query.userID);
var file = req.files.image;
console.log("File received : ");
//console.log("Image path : "+req.files.image.path);
res.json({result:"success"});
});