C# 允许用户使用 Ajax 下载文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/676348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 13:02:20  来源:igfitidea点击:

Allow User to Download File using Ajax

c#asp.netajax

提问by RC1140

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 articlebut i am not really keen on injecting iFrames into my webpage.

所以我需要通知用户下载正在进行中,甚至可能给他们一个进度条。我找到了以下文章,但我并不热衷于将 iFrame 注入我的网页。

Thanks in advance for any help.

在此先感谢您的帮助。

采纳答案by RC1140

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 方法,因为没有其他方法可以无缝地工作,值得花时间。

回答by Samiksha

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

在您的页面上添加一个进度条并为您的更新面板使用回发触发器。它将解决您面临的问题。

回答by JeremyWeir

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 或新窗口并让用户像使用浏览器一样管理下载有什么问题?