Losing extension when use FileReference download

后端 未结 4 720
醉酒成梦
醉酒成梦 2021-01-18 13:28

I need user download JPEG file from my app, however, when user change the file name the saved file will be downloaded without extension.

For Example: I am using File

相关标签:
4条回答
  • 2021-01-18 14:13

    you just need to use navigateToUrl(ur)

    var ur:URLRequest=new URLRequest();
    var fr:FileReference=new FileReference();
    fr.download(ur,<FILENAME>);
    

    "download" method call fileBrowser and then call servlet . then flex can't catch file extension

    but "navigateToUrl" called servlet first then servlet call fileBrowser then html can catch file extension

    0 讨论(0)
  • 2021-01-18 14:19

    I have the same problem and was not able to fix it until now. It seems it is a problem with flash + windows. :( sorry to inform but I did not found any fix.

    If this can be called a workaround, is somehow to warn users and ask them to place also the extension when they rename the file.

    0 讨论(0)
  • 2021-01-18 14:25

    Had same problem. Used CONCAT to manually add extension. It does not appear in the dialog box when saving but DOES save as a text file with a .txt extension when viewed in Windows Explorer. Doesn't seem to work but actually does!

    var final_filename:String = filename.concat(".txt");
    

    //Create text to save from text field var newDataFile:TextField = new TextField(); newDataFile.text=myTextField.text; //create file reference to save file var file:FileReference = new FileReference(); file.save(newDataFile.text, final_filename);

    0 讨论(0)
  • 2021-01-18 14:26

    This is a known problem with Flash Player. An enhancement request is filed with Adobe. Please visit and vote for it: https://bugs.adobe.com/jira/browse/FP-2014

    It does not seem practical to train users not to rename the file. Here is the workaround I use for my app:

    • The problem only happens on Windows with ActiveX plugin. Detect ActiveX with Capabilities.playerType (only ~25% of users in my experience)

    • If ActiveX plugin, fall back to 'navigateToURL()' to bounce the file on your server. Using this function is less desirable than FileReference.download() because it is less controllable (the browser is in charge, rather than your app), but it results in a Save dialog box where the user can rename the file safely.

    0 讨论(0)
提交回复
热议问题