2 Replies Latest reply on Jun 21, 2011 3:45 AM by ShardulSingh

    Help related to fileReference.download()

    ShardulSingh Level 3


      Hi All,


      I am working on downloading a file from the server inside an air application using the


      fileReference.download() method, on which the Download box opens.


      I am using the Windows 7 operating system. Can anybody suggest that is there any way to Change the 'Save as type' which is 'All Files(".")',to any particular type? I don’t found any way to applying the FileFilter during the download. If anybody has idea pleases Suggest.




      Alternatively, is there any way to override the behavior on the click of the ‘Save’ button, on the above mentioned download box? On the click of the Save button initially I want to fire some validations and then only I want to save the file to the file system. But the problem is whenever SELECT event fires, it surely saves the file to the file system. I want to stop this.



      with Regards,


        • 1. Re: Help related to fileReference.download()
          blazejewicz Level 4

          Hi Shardul,


          below will work but I don't think that is good solution for 3 important factors. Let's see solution:

          protected function downloadButtonClickHandler(event:MouseEvent):void


               var filename:String = defaultName+"."+defaultExtension;

               fileReference = new FileReference();

               fileReference.addEventListener(Event.SELECT, selectEventHandler);

               fileReference.download(request, filename);


          protected function selectEventHandler(selectEvent:Event):void


               // we have GO from user but check if she/he modified our default name/extension

               var name:String = fileReference.name.split(".")[0];

               var extension:String = fileReference.extension;

               if(name == defaultName && extension == defaultExtension)


                    // GO! and display Thanks! to user

                    debug("Thanks! Going down");

               } else {

                    // cancel pending operation



                    // now display SORRY to user and inform why operation is cancelled

                    debug("SORRY! operation cannot be proceeded due to filename: "+fileReference.name);



          Why this is bad?

          1) user can choose whatever name she/he want - for example your proposed filename could conflict with already existing content in directory that user chooses (we do not won't to overwrite someone beloved kitty image)

          2) the file type (extension) could set by user to custom type

          3) when you cancel operation - the bytes could be already written into file - and in fact if content is somehow cached - it will be written fully before "cancel" takes effect (and we are hitting the wall with flash.filesystem.FileReference - as there is no access to full path of that file located somewhere on user drive)


          What would be better solution?

          - I think you could use flash.filesystem.File:

          http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.h tml

          to let user only select target directory (where content would be saved) and then because you're using Air runtime use asynchronous URLStream to write bytes into local drive at location chosen by user with flash.filesystem.FileStream/flash.filesystem.File


          That solution would be more-user friendly in my opinion and would allow you to choose whatever names you want (as user won't be entering that bit of information),




          1 person found this helpful
          • 2. Re: Help related to fileReference.download()
            ShardulSingh Level 3

            Yes Peter,

              The issue is with the fileReference.cancel(); which is not able to cancel operation of the Saving to the file system.



            Rest fine with you approach of the Saving to a particular loaction as suggested by you without showing the Download Dialouge box,do agree with that.




            with Regards,