Non US-ASCII characters in download file names

I am trying to implement a simple file download in a JSP, and trying to get IE, Firefox and Opera to all display and handle non US-ASCII characters in the suggested download file name. Only concerned with Windows platform for now. Here's the code I am currently using:
String agent = request.getHeader("USER-AGENT");
if (null != agent && -1 != agent.indexOf("MSIE"))
String codedfilename = URLEncoder.encode(cfrfilename, "UTF8");
response.setContentType("application/x-download");
response.setHeader("Content-Disposition","attachment;filename=" + codedfilename);
else if (null != agent && -1 != agent.indexOf("Mozilla"))
String codedfilename = MimeUtility.encodeText(cfrfilename, "UTF8", "B");
response.setContentType("application/x-download");
response.setHeader("Content-Disposition","attachment;filename=" + codedfilename);
else
response.setContentType("application/x-download");
response.setHeader("Content-Disposition","attachment;filename=" + cfrfilename);
}This URL encodes the file name if the browser is IE, MIME encodes it if the browser is Mozilla, and sends plain UTF-8 (the encoding of the JSP) for all other browsers. I get "cfrfilename" from translated properties files, and the string can contain characters from any character set - Chinese, Thai, Korean, etc.
This code works correctly for IE - the file name is displayed correctly in the file Save as dialog, and it is saved correctly on disk, no matter which character set is used.
For Firefox, the file name is displayed correctly in the file Save as dialog, but it is only saved correctly to disk if the file name is in a character set supported by the system locale. This seems to be a known Firefox bug (not fully using the Windows Unicode APIs), so nothing I can do about that.
Nothing seems to work for Opera, however - I cannot get the file name to display correctly in the file Save as dialog, no matter which method I use (I have tried URL encoding and MIME encoding in addition to the plain UTF-8).
Has anybody implemented something similar that works for at least these 3 browsers?

I tested your code today,
                     dialog           save           open
Firefox 1.5          OK                 OK               OK
IE 6.0                OK                 OK                NGdailog: filename show in download popup dialog
save: save to disk from dialog
open: open directly from dailog

Similar Messages

  • Strange characters in downloaded file names

    Everytime I download a file that has a space or some kind of accent in it's name, I get some bizarre characters. For instance I get a %20% instead of every space in the file name...
    I guess it's an encoding problem but I haven't been able to find what the cause of the problem is or how to fix it. I've tried changing the default encoding in the Preference but doesn't change anything. I also tried to change the Language in the International System Preference panel, with no results.
    I've had this problem forever, but it's really frustrating to get this with what is supposed to be the most advanced operating system in the world. I've been bragging to my PC friends (well, they're not really friends, more like acquaintances) since 1984 about having no problems with accents, spaces, etc. in file names... and now...
    Please help.

    Everytime I download a file that has a space or some
    kind of accent in it's name, I get some bizarre
    characters. For instance I get a %20% instead of
    every space in the file name...
    It's not an encoding or language problem. Spaces are not allowed in urls, they must be replaced by %20, which is the escaped Unicode value for that character. Many servers do not accept spaces in the names of uploaded files, so the people uploading them delete spaces or replace them by underscores. But some servers do accept spaces in uploads and then replace them by %20. The same goes for accented characters.
    I don't think that there is anything unusual about what you are seeing, or that there is anything you can do about it.

  • Destination file characters too long (File names) , while copying from one external to another

    I have a external my book fat32 formated and a new mybook ntfs formated external as well.  Now when I copy my files from the fat32 to the ntfs external all files copy fine but some give that destination location file characters are too long, meaning that the file names are too long.  Now I could change the file names but that would conflict with programs that need that file name.  I am using vista ultimate and would like to copy all the files over from the fat32 to ntfs so I can reformat the fat32 to ntfs.  The files got on the ntfs from a simple drag and drop from my IDE NTFS internal hard drive.
    I hope you guys to tell me what to do.
    Thank you :)

    Here's the fix....for error message "your file name is too long to be copied, deleted, renamed, moved" :
    1.   problem is this: the "file name" has a limit on number of characters.....the sum of characters really includes the entire path name; you gotta shorten it first (i.e, if the total number of characters in the file name + Path name are over the
    limit, the error appears).  The deeper your file folder sub levels are, the more this problem will come up, especially when you copy to a subfolder of a subfolder/subfolder of another path ...adds to character limit)
    2.  How do you know which combined file names + path names are too long if  you are in the  middle of a copy operation and this error pops up?  Some files copied but the "long files error message" says "skip" or "cancel" ... but not which
    files are the "too long" ones.  If you hit "skip" or "cancel" the "too long" files are left behind...but are mixed in with non-offender "good" "short name" files.   Sorting thru 1000s of "good" files to find a few "bad" ones manually is impractical.
    3.   Here's how you sort out the "bad" from the "good":
    4.    Let's say you want to copy a folder ..."Football" ...that has five layers of subfolders; each subfolder contains numerous files:
      C:/1 Football / 2 teams/ 3 players/ 4 stats/ 5 injuriessidelineplayerstoolong 
           There are five levels root "1 football" with subfolders  2, 3, 4 and lastly "5 injuries"
    5.    Use "cut" and "paste"  (for example to backup all five levels to a new backup folder):
           select "1 football" ....cut....select target folder....paste 
           ("cut" command means as the files are copied to the target destination, the file is deleted from the source location)
          Hint: avoid "cut" and "paste" to a target folder that is itself a sub/sub/sub folder ...that compounds the "characters over the limit" problem ...because the characters in the sub/sub/sub folder are included in the "file name
    character limit"...instead "paste" to a C:/ root directory.
           Suppose in the middle of this operation...error pops up: "5 files have file names that are too long"  Skip or cancel?
           select "skip"  ...and let operation finish
    6.    Now go back and look at the source location: since the software allows only the "good" "short name" files to be copied (and because you "skipped" the "bad" "Long name" files so they are not copied or deleted) ...all that remains
    in the source location are the "bad" "long name files" (because "good" ones were deleted from the source location after the "cut" operation...the bad ones stick out like a sore thumb.
    7.   You will find ....all that remains in source folders are: the "bad" "too long" files; in this example the "bad" file is in level 5:
          C:/ 1 football / 2 teams /3 players /4 stats /5 injuriessidelineplayerstoolong
    8.   select folder 5 injuriessidelineplayerstoolong (that's right...select folder, not file) gotta rename the folder first.
    9.  hit F2 rename folder..folder name highlighted...delete some of the letters in the folder name:
           like this:   5 injuriessidelineplayers  ....you should delete 'toolong'....from the folder name
    10.  then go into folder 5....and do the same operation ...with the too long file name:
            hit F2 rename file....file name hightlighted...delete some of the letters
               like this:  injuriessidelineplayers.....you should delete 'toolong' from the file name
    11.  Now..."cut and paste"  the renamed file to the target backup folder.  
    The Error message will pop up again if you missed any "bad" files....for example, it will indicate "5 files too long" ....then repeat process 5 times until you fix all of them
    12.     Finally, copy the target destination files back to the source location (when you are certain all source location file folder locations are empty) 

  • "Download a copy" shrinks downloaded file name

    I'm using SharePoint Server 2013 with Russian language pack.
    When in a document library, I choose "Download a copy" menu item in ECB on a file, and SharePoint 2013 downloads a file correctly (it can be opened and the file content is OK), but the file name is trimmed on the local hard disk: downloaded
    file name is only a couple of first words long, but in a document library the file name is much longer.
    It happens only on files that have names in Russian (cyrillic characters). Files that consist of English characters are downloaded with correct names as they appear in a SharePoint document library. So, it seems not to be connected to a URL length restrictions.
    v

    Consider opening a PSS case on this. It does sound like a bug.
    Trevor Seward
    Follow or contact me at...
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • How to specify the download file name??

    Hi guys~~~
    I have servlet which can generate a *.pdf file,I found if I didn't setContentType="application/pdf",I can download it!!But the download file name is my servlet file name.If I want to change the download file name,How do I do????
    thanx a lot!!!Best regard!

    Thanx for ur help...But I encounter a new charllenge now...
    I use a javascript(window.open("/myservlet")) to open the download file servlet.
    Everything is okay.But when I finish downloading the file which window I opened cant close itself automatically.
    I am really not understand the header parameter of the HTML header,could someone give me something about this??
    Thanx again!!!!

  • Re number of characters in a file name with leopard.. 10.5.3

    re number of characters in a file name with leopard.. 10.5.3
    Is there a limit? in a file or directory name?

    hfs+ == hfs extended, the default filesystem on a current mac...
    http://en.wikipedia.org/wiki/HFS_Plus

  • Firefox doesn't reconvert special characters in the file names when download a file with any special characters in the file name

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [/questions/815207]</blockquote><br>
    if i try to download a file with any special characters in file name (e.g. File_Name.pdf), it doesn't reconvert them from the "sanitize url" process and download the file an incorrect name (e.g. File%5FName.pdf).
    This is really annoying.
    Thank you for your patient

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    * [[Troubleshooting extensions and themes]]

  • Non-ASCII Characters Appear In Path Name

    I've had this happen before over SSH via PuTTY on a Windows Host but now it's happening just in Linux. I'm testing out my first attempt at remastering the Arch Live CD and my home directory never got created while running rc.local, when I tried to execute it manually I got block characters at the beginning and end of the path. I tried to type the command manually and got the same thing. I enabled en_US ISO-8859-1 along with en_US.UTF-8 UTF-8 in /etc/locale.gen and re-ran locale.gen but it didn't seem to fix my issue. Anyone have any idea on how to fix this?
    Last edited by brando56894 (2013-08-30 17:01:04)

    What do you mean by non-ASCII characters?
    The ASCII character set contains characters for all byte values, however not all of them are displayable characters. Is it non-displayable characters you want?

  • Find Hidden Characters-in downloaded file

    All,
    I have a file interface that downloading file to SANS server using open dataset. But recently we are getting some hidden characters in the file. These are getting from a long text.
    Now my requirement is to find these hidden characters and display in the screen and user can correct then go for download.
    Currently i am using Notepad++ or using this link for finding the hidden characters
    http://string.online-toolz.com/tools/string-functions.php
    Now user wanted to use the same functionality with in SAP using ABAP.
    Any input on this appreciated.

    Similar functionality can be achieved by JavaScript. You can pass the entire Text and create your function in JS to find out the Hidden Characters. If you are successful finding the JS which can do this job for you, you can use [JS Engine|http://help.sap.com/saphelp_nw04/helpdata/en/49/a8e3c8d59811d4b2e90050dadfb92b/frameset.htm] available in ABAP.
    Refer to [ABAP & JavaScript|http://help-abap.zevolving.com/2011/10/javascript-in-abap/] to see the simple JS usage.
    Regards,
    Naimesh Patel

  • Special Characters in the file name in Data Driven Subscription via File Share

    Hi,
    I am trying to create a Data Driven Subscription with option to delivery as  windows file share in SQL server 2005. I need to save the report as a pdf with the following file name  '[City] City_Name', but it errors out and it is because of the
    Square Brackets. Is there any way i can save the file using the Square brackets as i mentioned above.
    I am using a query to get the filename and filepath. It works fine as long as i do not have [], but i need to save the file as i mentioned along with the Square Brackets.
    Please help.

    Hello,
    I can reproduce the issue on my test environment: When I create a Data Driven Subscription and specify the report name by get from a subscription delivery table, and the value of the "report name" column contains square brackets. The subscription failed
    with following error in the error log:
    ERROR: Error occurred processing subscription ab9523a6-0256-4607-b818-a7666204d018:
    The file name is not valid. Avoid using special characters such as /\?*:<>|+,[]"& in the file name.
    notification!WindowsService_1!1f24!05/30/2014-15:31:02:: i INFO: Notification 0cf5a356-3172-4108-9d8c-58ea81a0b80a completed.  Success: False, Status: The file name is not valid. Avoid using special characters such as /\?*:<>|+,[]"& in the
    file name., DeliveryExtension: Report Server FileShare, Report: Report6, Attempt 0
    It seems that the behavior is by design. please avoid using square brackets as file name. Maybe you can try to use parentheses () instead.
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Illegal characters in topic file names

    Robohelpers,
    I imported vintage MS Word files (dating from the early 90s)
    in to RoboHlep HTML. The topics generated correctly, but some of
    the characters in the the file names converted incorrectly, and are
    not recognized inside the program and the links to these topics are
    dead.
    The most common glitches:
    - The EN dash converts to an underscore, e.g. _–_
    appears on the disk as ___
    - The apostrophe converts to Æ
    The Topic list shows the correct characters. But since they
    don't agree with the physical file names, RoboHelp marks the icon
    with an "X".
    What's the best way to correct his situation, if you have
    hundreds of topics to deal with?
    I search for a solution without success. I can't believe that
    no one has encountered this issue before.
    Best regards,
    Charles Arnold
    MetLife DI
    Tampa, Florida
    I found a utility call "Rename" by on an Adobe web site, but
    it generated DLL conflict in my computer.

    Hello Charles -
    Are you posting to the correct forum? I ask because you
    posted that you're importing into RoboHelp HTML - this is the
    WebHelp forum. However, your situation can also occur with WebHelp.
    The problem is the Word files used Microsoft extended characters,
    the so-called "Smart" characters but that was dumb to use for
    anything that is converted to HTML. Do a mass search and replace
    for the "Stupid" quote, apostrophy and EN-dash and correct them to
    true HTML valid characters.
    Regards,
    GEWB
    See:
    http://tatumweb.com/typerat/ansirodent.htm

  • Allowable Characters in the file names within Oracle iFS

    What characters are allowable in file names within Oracle iFS?
    Are slashes (/ \) possible?
    Thanks,
    Sai Mummalaneni.

    Be carefull with file and directory names in iFS. You might be able to create folders and add document to it through the web interface that the windows explorer interface might not be able to interpret. Like a directory named '.'.
    Tamas Szecsy

  • %20 in Downloaded File Names

    Why in the **** do macs save downloaded files with a %20 everywhere there's a space in a document name and how do I make it STOP?
    Is there a utility one can download so that will make a Mac smart enough to recognize spaces?
    AAAAAhhhhhh!!!

    Might be corrupted preferences.
    Open a Finder window. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following:
    ~/Library/Safari/Downloads.plist
    Click Go then move the Downloads.list file to the Trash.
    Quit and relaunch  Safari to test.
    If that didn't help, copy and paste the following
    ~/Library/Preferences/com.apple.Safari.plist
    Click Go then move the com.apple.Safari.plist file to the Trash..
    Quit and relaunch Safari to test again.

  • Javamail API doesn't support special characters in attachment file name

    Hi,
    We are using Java Mail API to retrieve the attachment's file name, but it sometimes returns the file name as junk character (if the attachment contains special characters) and it is not able to return original file name for some attachments:
    Our code sample :
    void getFileName(Part part) {
    String fname=null;
    fname = part.getFileName();                          
    Actually the problem is with the attachment file name which contains special character. For example below is the attachment file name (please find the sample attached file which is causing this issue):
    Sample – 1234abc.doc
    From above you could see the file name contains a special character (Sample – 1234abc.doc), i.e. The character ‘–’ is not a regular hyphen character, it’s a special character. Hence the Java mail API returns the name as below:
    Sample ? 1234abc.doc
    So the special character is being replaced with ‘?’ symbol. But if I store this file in local folder and try reading the file name using Java IO packages, it returns the file name without adding ‘?’ symbol.
    Is there any way to handle such kind of special characters in Mail API?
    Regards,
    Vinodh

    We dealt with this issue in a private email conversation.
    JavaMail is returning the correct data for the filename.  The problem is in the way the filename is being displayed.

  • How do I remove spaces and special characters from the file name during rendering?

    I understand that I can set LR_renamingTokensOn to true, but I would like to replace all spaces in the file name with an underscore and remove characters not in the range A-Z and 0-9. What's the easiest way to achieve this?

    local photo = catalog:getTargetPhoto()
    local sesn = LrExportSession {
        photosToExport = { photo },
        exportSettings = {
            -- ... (determine from export preset) - whatev you want, just be sure you set export directory: LR_export_destinationPathPrefix
            LR_tokens = "{{custom_token}}",
            LR_tokenCustomString = LrPathUtils.removeExtension( photo:getFormattedMetadata( 'fileName' ) ):gsub( "[ %c]", "" ) -- remove spaces and control characters
    sesn:doExportOnNewTask()

Maybe you are looking for