delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

Uploaded files always come as application/octet-stream #9

Closed rbaprado closed 9 years ago

rbaprado commented 9 years ago

Hello,

Is there a way to fix this? My backend depends on the mime-type to detect valid images and has problems to receive files from Android because of this...

Thanks.

ocram commented 9 years ago

Thanks for pointing this out. We haven't checked this yet, so can you tell what platform versions this happens on?

By the way, you should neither rely on file extensions nor on MIME types for security checks. For all other purposes, that may be fine, of course.

rbaprado commented 9 years ago

I tested on 4.4.4 and 4.1.2, the behavior is the same.

Thanks for the advice, my application does not rely on mime types anymore due to the security risk you pointed out, but I came across this issue and thought it might be a good feature. Em Fri Jan 23 2015 at 18:26:17, Marco notifications@github.com escreveu:

Thanks for pointing this out. We haven't checked this yet, so can you tell what platform versions this happens on?

  • Android 4.3 and below
  • Android 5.0 and above
  • both

By the way, you should neither rely on file extensions nor on MIME types for security checks. For all other purposes, that may be fine, of course.

Reply to this email directly or view it on GitHub https://github.com/delight-im/Android-AdvancedWebView/issues/9#issuecomment-71259692 .

ocram commented 9 years ago

Well, on 4.4.4, file uploads should not be available at all. Apart from that, you're right, file uploads should work as in the user's normal browser.

We have tested MIME type detection with this library and it seems to work as intended. Generally, most browsers detect the MIME type by looking at the file extension, anyway.

Can you please check what MIME type is detected if you upload the same image from your desktop browser or from the Android system browser?

ocram commented 9 years ago

This has now been tested on platforms both with the old WebView (4.3 and below) and with the new Chromium WebView (5.0 and above).

File uploads are working fine and MIME types are added by the WebView as well, e.g. like this:

Content-Disposition: form-data; name="my-file-input"; filename="my-file.png"
Content-Type: image/png

You should inspect the raw HTTP request and see if you're receiving this as well. If not, this may be due to the file you upload, the form HTML or the browser that is used -- but it seems at least with this library, everything is fine in that respect.

rbaprado commented 9 years ago

I will look into that. Just to let you know that I will be working for the next few days in another project, so, don't hold you breath :-)

Thanks for the support, though.

Em Fri Jan 23 2015 at 22:11:23, Marco notifications@github.com escreveu:

This has now been tested on platforms both with the old WebView (4.3 and below) and with the new Chromium WebView (5.0 and above).

File uploads are working with and MIME types are also added by the WebView, e.g. like this:

Content-Disposition: form-data; name="my-file-input"; filename="my-file.png" Content-Type: image/png

You should inspect the raw HTTP request and see if you're receiving this as well. If not, this may be due to the file you upload, the form HTML or the browser that is used -- but it seems at least with this library, everything is fine in that respect.

Reply to this email directly or view it on GitHub https://github.com/delight-im/Android-AdvancedWebView/issues/9#issuecomment-71288502 .

ocram commented 9 years ago

It turned out there is some special (and wrong) behaviour on Android 4.4.3 and 4.4.4 which is explained here: https://github.com/delight-im/Android-AdvancedWebView/issues/14