Question

I've posted a similar topic on this issue, but that was more for discovery than comprehensive solution. I've discovered without a doubt that the Android Chrome browser is unable to handle UTF-8 encoding in the file name in the CONTENT-DISPOSITION httpResponse header. Here is my example httpResponse header: 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

Here is the C# .NET code I am using to encode the file name:

// This is RFC5987 format, specifying use of utf-8. Apostrophes must be encoded for Chrome. contentDisposition = "attachment; filename*=UTF-8''" + Uri.EscapeDataString(fileName).Replace("'", Uri.HexEscape('\''));

I'm testing on a Nexus 7 device and the Firefox and Dolphin browsers are able to handle the UTF-8 encoding correctly. I work for an international company, so it is absolutely essential for the file name to be able to contain non-ascii characters. I've included the background info as well as the issue. The "Download" attribute doesn't overwrite the file name since the url is not physically pointing to the file.. I'm using mvc routing, so the download attribute gets ignored (the file name in content-disposition is used instead). Anybody know a possible workaround for this? Is it possible to somehow encode the file name for Android Chrome with utf-8 and then overwrite the altered "Download.bin" file name so that it downloads with the correct name?

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.

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 or MVC routing 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 would appreciate any help.

NOTE: I've tried the latest beta of Android Chrome, and the utf-8 encoding in the file name doesn't work on that browser as well. The file gets renamed to "Download" or "Download.bin". So, it looks like Google might not be fixing this any time soon...

Was it helpful?

Solution 2

It turns out that file names don't need to be UTF-8 encoded for non-ascii characters for the Android Chrome browser. I was able to successfully download a file using Android Chrome with Korean characters in it without encoding it with UTF-8. I'll have to do more tests before I can 100% confirm this.

OTHER TIPS

This is indeed a bug in both the stock Android browser and Chrome in Android. At least for the latter, a bug should be reported.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top