apache-flexflash-builderfilereference

How to fileRef.download(request) programmatically


I am able to download a file from my server when a user clicks a button in the on clicked event handler, but I have to first create the file on the server with a service call. In my on success method I can then download the file for the user. When I do this, however, I get the following error

Error: Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.

I think I understand the error in that the download pop up window can only be invoked from a user interaction. How can I work around this. I am doing it in response to a user interaction, but I cannot execute the download until after the server has created the file.


Solution

  • The reason that functionality is there is for security purposes. I would say there is no way to "Get around this"; but you can consider alternate implementations. Here are a few:

    1) Give the user an interface. The first button click says "preparing file for download" and the when you get the resource back; change the button to "download now". That way you force user interaction for the download.

    2) Immediately launch a URL to the server side template that will generate the file and return it. If the process is relatively quick the user probably won't care.

    3) Switch to an AIR app which does not include as many restrictions in access to the local file system.