I am having below code to upload an image from Android to a web server.
It works fine except that the received image is of Content Type Octet Stream and I need it to be Content Type Image. Any idea how I can set the content type?
public void sendImage(final Bitmap mBitmap, final String caption, final WebListener webListener) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
AQuery aq = new AQuery(smApplication);
Map<String, Object> params = new HashMap<String, Object>();
params.put("file_name", "name" + (int) (Math.random() * 1000));
params.put("caption", caption);
ByteArrayOutputStream blob = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, blob);
byte[] bitmapdata = blob.toByteArray();
params.put("photo", bitmapdata);
AjaxCallback<JSONObject> ac = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject object, AjaxStatus status) {
if (status.getCode() == 200) {
try {
String success = object.getString("success");
if (success.equals("postCreated")) {
webListener.onCompleted(true);
}
} catch (JSONException e) {
webListener.onServiceError(e.getMessage());
}
} else {
error(status.getError(), webListener);
}
}
};
ac.header("Authorization", "Token token=" + Cache.getInstance().getDeviceKey());
aq.ajax(HOST + API + "posts", params, JSONObject.class, ac, "photoCb");
}
});
thread.start();
}