问题
I thought I'd repost this since I have more detailed information:
THE ISSUE: Android Chrome browser renames a file to "Download" in all cases. It renames the type to ".bin" in some instances (if the extension is .MOV, for instance). As I've mentioned before, the Firefox and Dolphin browser apps on the same Android device don't exhibit this behavior. The files are downloaded correctly. As a side note, I already tried specifying a "Download" attribute within the Anchor element with no luck. The "Download" attribute gets ignored even by the Android Chrome browser in this case. My hunch is that it's because of the way we're streaming the file that the "download" attribute is being ignored. Another thing to note is that the desktop version of the Chrome browser downloads files without the issue (no renaming). I think there's some security feature built into the Chrome browser that is causing these renaming probs.
BACKGROUND INFO: The web server is IIS 7.5 on a Windows Azure cloud. The web application in use is Microsoft's MVC framework for routing. So when a file is selected to download from the Chrome browser within an Android device, a download method on the server is accessed using MS MVC routing. Within this method, we're specifying the header information and streaming chopped up pieces of the file using httpResponse. This works beautifully for any other browser app on the Android device (Firefox and Dolphin, for instance) and is able to save with the correct file name and type. With Chrome, however, the file and type (sometimes) gets renamed.
Here are the response headers when I download a .MOV file:
*HTTP/1.1 200 OK Cache-Control: private, s-maxage=0 Content-Length: 54295903 Content-Type: application/octet-stream Server: Microsoft-IIS/7.5 X-AspNetMvc-Version: 4.0 Content-Disposition: attachment; filename=UTF-8''MyVideo.MOV X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Sat, 29 Jun 2013 05:01:32 GMT**
HELP!: I would appreciate any advice on a work-around. Also, I would appreciate a definite word from somebody who works in the Google dev community as to whether this will be fixed in the next refresh. Thanks!!
回答1:
Content-Disposition
has a history of being a problem on Android. You are certainly welcome to try removing the UTF-8
part and see if that helps Chrome. But definitely test the original Android Browser app as well, as numerically that's the most popular browser for Android.
See also:
- http://code.google.com/p/android/issues/detail?id=11422
- Android browser/webview bug? Content-Disposition: attachment; filename="xyz.txt"
- http://code.google.com/p/android/issues/detail?id=9991
- http://thedigiblog.wordpress.com/2011/04/19/android-and-the-download-file-headers/
回答2:
I had a similar problem with downloads on Chrome/Android. .docx files were renamed to filename.bin (or something like that).
Headers included
Content-Type:application/octet-stream
and
Content-Disposition:attachment; filename="something.docx";
Turned out that my problem was in trailing semicolon in "Content-Disposition" header. When there is no semicolon at the end of the line - it works fine:
Content-Disposition:attachment; filename="something.docx"
More info here: http://www.digiblog.de/2011/04/android-and-the-download-file-headers/
So, be sure to check that as well.
回答3:
This a duplicate of a previous question we answered live on air and on SO here https://stackoverflow.com/questions/17266320/chrome-browser-in-android-always-renames-downloaded-file-to-download-bin which has been deleted.
This will be fixed in the next refresh especially via the a[download] attribute.
来源:https://stackoverflow.com/questions/17374621/android-chrome-browser-unnecessarily-renames-names-types-of-downloaded-files