0

I'm trying to upload a file to a django server from an android phone, and i'm getting a strange mimetype. My code utilizes the Asynchrnous HTTP request client, and I'm using the below code:

File file = new File(/*Get file*/)
RequestParams params = new RequestParams();
params.put("file", file);

getAsyncHttpClient().post(url, params, new JsonHttpResponseHandler() {
    public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
        error.printStackTrace();
    }

    public void onSuccess(final JSONObject obj) {
        Log.i(TAG, obj.toString());
    }
});

The content-type I'm getting on the server from a django FileField is application/octet-stream. Is there anyway to get the real mimetype to be passed in? I have been researching on this for sometime.

I read these below links:

Uploading an image from Android (with Android Asynchronous Http Client) to rails server (with paperclip)

Android image file sent to php upload image file is application/octet-stream type and not image/jpeg?

Is there something else I should be passing into the Android Asynchronous Http Client?

Community
  • 1
  • 1
KVISH
  • 12,923
  • 17
  • 86
  • 162

1 Answers1

0

Can't believe I didn't see this before.

http://loopj.com/android-async-http/doc/com/loopj/android/http/RequestParams.html

You can just do:

params.put("file", file, mimetype);
KVISH
  • 12,923
  • 17
  • 86
  • 162