Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow User to Download File using Ajax

Tags:

c#

ajax

asp.net

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.

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.

Thanks in advance for any help.

like image 708
RC1140 Avatar asked Mar 24 '09 06:03

RC1140


People also ask

Can we download file using AJAX?

You need to set it according to your file type. You can use this technique to download any kind of files. "We cannot download the file through Ajax, must use XMLHttpRequest". XMLHttpRequest is AJAX by definition.


2 Answers

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?

like image 90
JeremyWeir Avatar answered Sep 20 '22 05:09

JeremyWeir


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

like image 44
RC1140 Avatar answered Sep 24 '22 05:09

RC1140