允许用户使用Ajax下载文件

时间:2022-01-13 09:45:23

I am looking for a way to allow users to download a file from my site using ajax. The reason why i need to do this is because the files are quite big (50 megs normally). So when the user clicks the download button it actually looks as if the page is not responding because it has to stream the file from my Amazon S3 to the user.

我正在寻找一种允许用户使用ajax从我的站点下载文件的方法。我需要这样做的原因是文件很大(通常是50兆)。因此,当用户单击下载按钮时,页面看起来似乎没有响应,因为它必须将文件从我的Amazon S3流到用户。

So i need to notify the user that the download is in progress and maybe even give them a progress bar. I have found the following article but i am not really keen on injecting iFrames into my webpage.

所以我需要通知用户下载正在进行中,甚至可以给他们一个进度条。我找到了下面的文章,但是我并不是很喜欢在我的网页中加入iframe。

Thanks in advance for any help.

谢谢你的帮助。

3 个解决方案

#1


5  

I don't really see how you can allow a user to download a file using ajax. There won't be any way to get the file to their filesystem from javascript. What's wrong with targeting the file into an iframe or a new window and letting users manage the download like they are used to using their browser?

我不知道您如何允许用户使用ajax下载文件。没有任何方法可以从javascript将文件放到文件系统中。将文件定位到iframe或新窗口并让用户像习惯使用浏览器那样管理下载有什么问题?

#2


2  

I have decided to use the IFrame method is there is no other way that works seamlessly enough to make it worth the time.

我已经决定使用IFrame方法,没有其他方法能够无缝地工作,使它值得花费时间。

#3


1  

Add a progress bar on your page and Use postback triggers for your updatepanel. It will solve the issue you are facing.

在页面上添加进度条,并为updatepanel使用回发触发器。它将解决你所面临的问题。

#1


5  

I don't really see how you can allow a user to download a file using ajax. There won't be any way to get the file to their filesystem from javascript. What's wrong with targeting the file into an iframe or a new window and letting users manage the download like they are used to using their browser?

我不知道您如何允许用户使用ajax下载文件。没有任何方法可以从javascript将文件放到文件系统中。将文件定位到iframe或新窗口并让用户像习惯使用浏览器那样管理下载有什么问题?

#2


2  

I have decided to use the IFrame method is there is no other way that works seamlessly enough to make it worth the time.

我已经决定使用IFrame方法,没有其他方法能够无缝地工作,使它值得花费时间。

#3


1  

Add a progress bar on your page and Use postback triggers for your updatepanel. It will solve the issue you are facing.

在页面上添加进度条,并为updatepanel使用回发触发器。它将解决你所面临的问题。