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 FileReference.download() and set the default filename as "demoPic.jpg" and user's windows system setting control file extension not being shown. So when the dialog opens a download window, only "demoPic" shown as the filename. If user saved file without changing filename, the saved file will be OK. But if user change file name, the download file will be saved without extension. is it possible to add file extension to fil开发者_开发知识库ename when user forget it by flex code?
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.
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.
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);
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
精彩评论