开发者

Flex File download

开发者 https://www.devze.com 2023-04-10 05:58 出处:网络
I\'m currently working on a Flex3/blazeDS/Spring/Oracle project. My requirement is display a list of files from an external FTP server in a grid, user can select si开发者_StackOverflowngle file or mul

I'm currently working on a Flex3/blazeDS/Spring/Oracle project. My requirement is display a list of files from an external FTP server in a grid, user can select si开发者_StackOverflowngle file or multiple files to download, and if user selects multiple files I should tar the files on the FTP server and download the tar file from FTP server to user disk. As per my understanding on the File Download in Flex we have 2 ways to do it. 1) File Reference 2) Using navigateURL and call server side JSP/Servlets to download files.

1) For FileReference we need to download the data first and prompt the user to save the file by clicking on some button. We cannot prompt the 'Save' dialogue without the click event for Security reasons in Flex (Workaround). But my client hates this process because its two steps and he want it in one step like normal file download with only 'Save' dialogue. Then I tried the second option.

2) navigateURL. Open a new windows make a post url request for to JSP/Servlets and prompt the 'Save' dialogue. The problem I am facing here is the pop-up window does not close once the download is complete. navigateURL does not return any reference to the window to close the window. I even tried different content types and headers and java script but none seems to work. The window closes when it is a single file and not for the tar or zip file. I would like to download the popup window for any type of downloads. I am using IE7.

Any help or any other possible solutions are appreciated. Thanks in advance.


You could use a hidden iframe. This way there is no popup/new tab involved, just the "save" dialog.

To do this you need to use some JavaScript on the page. Something like this should do it:

<script language="JavaScript" type="text/javascript"> 
function makeFrame(theUrl) { 
   ifrm = document.createElement("IFRAME"); 
   ifrm.setAttribute("src", theUrl); 
   ifrm.style.width = 640+"px"; 
   ifrm.style.height = 480+"px"; 
   document.body.appendChild(ifrm); 
} 
</script> 

To call the function from Flex use the ExternalInterface

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号