Fix extension when using FileReference

I need to download a JPEG file from my application, however, when the user changes the file name, the saved file will be downloaded without the extension.

For example: I use FileReference.download () and set the default file name as "demoPic.jpg", and the custom window installation control file extension is not displayed. Therefore, when the download window opens in the dialog box, only "demoPic" is displayed as the file name. If the user saved the file without changing the file name, the saved file will be in order. But if the user changes the file name, the download file will be saved without extension. Is it possible to add the file extension to the file name when the user forgets it using flexible code?

+6
flex actionscript-3 download
source share
5 answers

I have the same problem and I have not been able to fix it so far. This seems to be a problem with flash + windows. :( sorry to report, but I did not find any fixes.

If this can be called a workaround, you need to somehow warn users and ask them to also place the extension when renaming the file.

+1
source share

This is a known issue with Flash Player. An improvement request is submitted to Adobe. Please visit and vote for him: https://bugs.adobe.com/jira/browse/FP-2014

It is practically not possible to train users so that they do not rename the file. Here is a workaround that I use for my application:

  • The problem only occurs on Windows with the ActiveX plugin. ActiveX detection with Capabilities.playerType (only about 25% of users in my experience)

  • If the plugin is ActiveX, go back to 'navigateToURL ()' to scan the file on your server. Using this function is less desirable than FileReference.download (), because it is less controlled (the browser works, not your application), but as a result, the Save dialog box appears, in which the user can safely rename the file.

+2
source share

There was the same problem. Used by CONCAT to manually install the extension. It does not appear in the dialog box when saving, but saves it as a text file with the extension .txt if it is displayed in Windows Explorer. It doesn't seem to work, but it actually does!

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

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

+1
source share

you just need to use navigateToUrl (ur)

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

The "load" method call the Browser file, and then call the servlet. then flex will not be able to catch the file extension

but "navigateToUrl" first calls the servlet, and then calling the fileBrowser servlet then html can catch the file extension

+1
source share
 protected function downloadImage():void { loadImage(); } public function loadImage():void { var NowDate:Date=new Date(); var dateStr:String=String(NowDate.date)+'-'+String(NowDate.month)+'-'+ String(NowDate.fullYear)+' '+String(NowDate.hours)+'-'+String(NowDate.minutes)+'-'+String(NowDate.seconds); var file:File= File.desktopDirectory.resolvePath('image_'+dateStr);; file.addEventListener(Event.SELECT,onSelect); file.browseForSave("Save image"); } public var filePath:String=''; public var fileName:String=''; public function onSelect(event:Event):void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadcompleteHandler); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioError); loader.load(new URLRequest(img_path)); fileName=event.target.name; filePath=event.target.url; } private var _bitmapData:BitmapData; public function loadcompleteHandler(event:Event):void { var loaderInfo:LoaderInfo = event.target as LoaderInfo; var bitmap:Bitmap = loaderInfo.content as Bitmap; _bitmapData = bitmap.bitmapData; var imgByteArray:ByteArray; var jpegEncoder:JPEGEncoder = new JPEGEncoder(80); imgByteArray = jpegEncoder.encode(_bitmapData); var file:File = new File(filePath+'.jpg'); var fileStream:FileStream = new FileStream(); fileStream.open(file, FileMode.WRITE); fileStream.writeBytes(imgByteArray); fileStream.close(); pop.status_text("Photo Downloaded Successfully",1); } 
0
source share

All Articles