Android Multipart HTTP Post does not send the File's MIME type

后端 未结 6 1166
挽巷
挽巷 2021-02-05 21:53

Trying to figure what\'s wrong with my codings. I followed a blog post from here.

I managed to get the codes to actually upload the file to a PHP web service. However, f

6条回答
  •  遇见更好的自我
    2021-02-05 21:59

    I had the same problem and just fixed it.

    I found that using the HttpMultipartMode.BROWSER_COMPATIBLE prevented the correct mimeType from being set in my request, when using a ByteArrayBody for an image. I assume this is probably the same problem you are having.

    When I changed this line:

    MultipartEntity mp = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    

    to

    MultipartEntity mp = new MultipartEntity();
    

    then the mime type was set correctly and the service upload worked.

    I see that people used the BROWSER_COMPATIBLE for solving another problem, but hopefully you don't need it.

提交回复
热议问题