【问题标题】:Mimetype of file uploaded to django上传到 django 的文件的 Mimetype
【发布时间】:2014-02-19 05:21:32
【问题描述】:

我正在尝试从 Android 手机将文件上传到 django 服务器,但我得到了一个奇怪的 mimetype。我的代码使用了异步 HTTP 请求客户端,我正在使用以下代码:

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

我从 django FileField 在服务器上获取的内容类型是 application/octet-stream。有没有办法让真正的 mimetype 被传入?我一直在研究这个。

我阅读了以下链接:

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?

还有什么我应该传递给 Android 异步 Http 客户端的吗?

【问题讨论】:

    标签: android django file


    【解决方案1】:

    不敢相信我以前没见过这个。

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

    你可以这样做:

    params.put("file", file, mimetype);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 2011-03-27
      • 2011-04-14
      • 2020-08-05
      • 2017-08-17
      • 2014-11-02
      相关资源
      最近更新 更多