Download large files with ajax






















Post as a guest Name. Email Required, but never shown. The Overflow Blog. A conversation about how to enable high-velocity DevOps culture at your Podcast An oral history of Stack Overflow — told by its founding team. Featured on Meta. New responsive Activity page. Linked Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings. You can also create the link dynamically, and invoke a click on it so that the user has to click once to download the file.

Updated on January 3, Published on February 6, Demo Download Starting Download.. In this Tutorial. Jake N Jake N Thx for that :. Since it and other similar tools out there simply uses the html 'file' input type to render and upload files.. Of course. Someone could eat up your bandwidth easily. But your considering security holes now before developing which is good. You can therefore do you best to fill those holes early rather than later. The Overflow Blog. A conversation about how to enable high-velocity DevOps culture at your Podcast An oral history of Stack Overflow — told by its founding team.

Featured on Meta. New responsive Activity page. Linked 0. Looking forward to your suggestions and any corrections to the approach I adopted. I implemented the code in vb. No error in show but it just does not download. This plugin does not work if Content-Disposition: inline; is returned.

Nothing happens. How to open pdf file in new tab using this? Using version 1. I searched on the internet and send you a diff file I don't have a github account, sorry for the following changes : add a name for iframe, target form to it. But its default size is unpractical. For browsers which prompt user, non-hidden frame border is visible, and it just blinks on file download, right before prompt displays. Thank you for your feeback about this and the patch I propose. I'm having problems setting the cookie from a WebAPI controller.

Anyone have an idea on how to accomplish this? Glad the plugin is working for you. Perhaps I can include that in a future commit. Feel free to contribute on GitHub in the mean time if I don't get to it for awhile. Anyway, short question. I checked the source code, but couldn't find anything.

I would try stepping through the jQueryFileDownload source and see why the callback isn't getting called. I don't think it's an issue with the code since it appears to be working in the demo but you never know. If I were to throw a guess out there I would think that perhaps the cookie is being written incorrectly. I am having a few problems using the code from your "Custom rich user experience — jquery. The modal dialog opens and the file download completes, but the dialog box does not close.

It is not clear that the successCallBack function is ever called. The response header for the downloaded file has the appropriate settings for the cookie, as you describe in the documentation, so I'm not sure what might be broken. Also, the text "We are preparing your report, please wait…" never appears in the dialog.

This behavior is true for both Firefox I am having problems with getting the dialog to close. Files are successfully downloaded, but the dialog remains open after the download. I am using the code snippet from your "Custom rich user experience" that employs the 'preparing-file-modal' divs. The cookie is correctly returned in the response header, so I don't believe that is the problem. Also, the text in the dialog "We are preparing your report, please wait…. This problem occurs in both Firefox Any clues on what I should be checking would be appreciated.

John, I managed after all. I can recognize empty download on server side, so I sent the same cookie but with different value.

Then I copied your check of a cookie and callbacks and made emptyCallback available. Now I have success, empty download and error as three different paths with three different feedbacks for user. Thank you again very much. I'm not aware of any way around it at this point unfortunately. Very interesting plugin and it works for me except for IE7.

Trouble in my case is, that the download may be empty, in which case failCallback is used. In IE7, however, this is not enough. But the question is — is there any other way how to treat empty download differently? What if real error occured on the server — then I can't distinguish it from empty response which I have to mask as I originally tried , which was probably deep misunderstanding on my part — this rather refreshed the whole page in the browser.

I'd welcome any suggestions as I'd love to use this plugin in our future works, it seems quite reliable when I stick to code for errors and the experience is just great. Users just can't be talked out of wanting to disable buttons and then enable them again, so we have to use something like this. If I remove uncomment that line, everything loads fine. I have updated the GitHub and the demo site with a setTimeout 0 around the cleanup which should clear the stack before cleaning up hopefully fixing the issue.

I'm unable to get it to happen now. Anyone please let me know if you can get it to happen again, thanks! I confirm that for firefox there is problem. It'll fail silently and randomly even on demo for success case. If I DO add the SetCookie to the header, it may be 2 or 3 clicks before I see the dialog asking whether I want to open or save the file, but the file save dialog never appears after I click "Ok" on that one. However, the callbacks don't get called until that dialog goes away, which is what I'd expect.

I need to use this plugin with coldfusion 9. Here I found demo with ASP. I want to use this with coldfusion. No idea how to manage code related to cookie as shown for ASP. Any idea?! This is in response to Andrew Laws and anyone else experiencing intermittent failures to get prompted to save a file. The problem appears to be due to the iframe getting removed too quickly. I solved the problem by changing line of v1. The added delay seems to clear up the problem.

A better solution might be to check and see if the iframe already exist when it is being created and if so, remove the existing one first.

If you are using. If you have httpOnlyCookies on you won't be able to read the cookie client side and it won't work. I think this might even be the default option.

Example: A checklist sends a lot of params with the same name, so the server is waiting a list like object. This tool is really useful. I have it working but it would seem that it doesn't work for ALL extensions of files. At least that's my conclusion after trying to download 5 files with the same name but different extensions. Some were downloaded but to the others appeared the "A file downloaded error …" box and didn't download.

And it's happening a funny thing in IE. When I request the download, the save box shows up but also the error box when downloading known extensions. Just wondering if anyone else has noticed an intermittent failure with this plugin when using Firefox?

This is with a "straight" out of the box Firefox install v Chrome, Opera, Safari and, yes, even IE! There is absolutely no indication that anything has gone wrong apart form this.

When the failure occurs, it's not permanent, and clicking on the link again usually gets me the file but it still fails intermittently afterwards. I've tried to figure out what's going on by installing the FireBug extension and debugging, but I can't track down the difference between the successes and failures. The flow of execution seems the same in both cases. Having said that, I have noticed that:. For example, if my test file takes 5 seconds to prepare, and I set the checkInterval to i.

Also, it could just be that I have been lucky and not seen it under those conditions — the usual problem with the intermittent problems…. Good idea on checking the iframe's readyState. Your right though, unfortunately when I was testing this approach Chrome didn't work.

Each browser that did work had different things happen to the readyState of course right? Thanks for the thought! My successCallback is never called because if document. I can't help but think though, is the cookie component even necessary? The iframe state can be tested using. I have used the same code that you have given but in simple ASP.

Net , What should be the URL Passed in the link , I am giving the path of the pdf, But it is going to the Failure , what could be the reason, I will be really great full if you can help me on this. Plugin is unable to download 'dat' and 'jpg' files. I am not sure whats going wrong? Your comments would be appreciated. There is a issue for Firefox, if my FF prompts me selecting the path to download, and at that time, the temp iframe has already been removed, so the download will not continue, anyway can detect the save as dialog?

I took a look at the site indicated and it doesn't appear to be running anymore. The cookie should be written along with the response stream that contains the file. The cookie needs to be included in a header with that. Hopefully this helps! Not sure if I've done this right. I have a gaming site and i'm trying to use your script to give the. I've included your modal dialog version of the script.

What I'm not sure is about the server side cookie. I use a redirect script to track all the download requests in PHP. Prior to setting the header location, I'm setting the cookie to your PHP line above. What happens on IE is that the download script reports a failure, but successfully executes the request. On the Mac which is not really needed at this moment, but will be later it flashes the processing dialog and doesn't execute the download at all.

I would have to write a proxy streaming script to know when its done since I'm linking outside my site. Not a big deal, but not something I saw noted in your example. I'm not sure what could cause that issue without doing local debugging of it. Make sure that you have added a script reference to jQuery before your script reference to jQuery file download.

Also try calling jQuery file download with the exact same syntax as mentioned in one of my posts to make sure its not a syntax issue for starters. Hope you get it figured out. Are you writing a cookie along with your file download? Unfortunately this is the only way to detect file downloads reliably cross browser. Make sure using FireBug, Chrome, Fiddler etc. I hope this helps! Is never true, so it doesn't stop, and no success function is fired.

It happens on last versions of FF, Chrome and safary. Without it knowing any better it probably just spawns up a browser to deal with that event since IFRAMEs are generally junk except in this one case, ha! Unfortunately this is probably permanent so you may need to find a different solution perhaps using native code in the device you are targeting even?

First of all, great Plugin. Really usefull. I tried in my webbrowser, working properly. Does it work on webkit? I mean it does but actually I decided to include this into my phonegap app using jQuery Mobile and when i click the link it leaves the application and redirect to the native browser.

Did I miss something? I have fully tested in native IE installs and everything appears to work properly in my demo. IE Tester is a pretty cool thing for high level testing I use it for starters on everything that I need cross IE browser support but sometimes it gets a little weird with things so I'll always finish off testing in a native install. Too bad you can't run multiple IEs on a single box right…. I'm updating the post to include tested browsers.

Let me know if you notice anything else or can think of some cool features to add! The file download dialog does not show after the initial file generation animation completes. I don't personally have IE8 installed, but used IETester instead and is supposed to give accurate behavior. Author required. Email will not be published required. We are preparing your report, please wait There was a problem generating your report, please try again.

CheckAndHandleFileResult context ;. OnResultExecuting context ;. Result is FileResult. AddYears - 1 ;. Reply Angar14 Jun 25, pm hi John How can I redirect to a different page after downloading the file? Thank you and good work! Reply Serdar Mar 4, am Hi, Great plugin! Is it possible to download excel file by getting ajax data response from ajax?

Reply Manoj Dec 19, am Hi I have to servers abc. Any feedback would be greatly appreciated. Please keep us informed like this. Reply dee Nov 20, am Thank you for sharing your work. Reply Alex Oct 25, am Hi, I am receiving next exception when trying to download a big csv file from my instance DOMException: Blocked a frame with origin "" from accessing a cross-origin frame. Reply Alex Oct 27, am v1.

Reply Daniele Jun 16, am Hi. Thank you. This blog gives useful facts to us, keep it up. Reply Manny Jan 31, am Thanks so much for this!! How About You? I Didn't know that! Reply Saroj Dec 13, am How to use this in angularjs. If a run F12 I can see the file in the response.

Reply Joe Kahl Oct 25, am John, I recently fixed a bug in our web app that required me changing your code. Sincerely Joe Kahl. Reply Diego Oct 14, pm Hi Luciano, I think you should use file stream instead of file download, like the example from this link.

Reply Steve B Nov 22, pm I am about to move forward with the jquery. Reply Alejandro Sep 22, pm What do I need to do to implement authorisation headers?

Reply proshank Sep 22, pm Did you find solution for this? Reply www. Reply regalos para mujer Jul 29, pm But where some have accepted these myths as reality, others have not and have gone on to achieve great things and live great dreams. Reply Junes Jul 12, pm Thanks John, your plugin is very useful in my project, its a big help for me!

Reply Smithe May 8, pm This is why Facebook games are becoming more popular. Reply George Mar 3, am Thank you for this plugin, I managed to overcome my problem in. Reply Seema Mar 1, am Hi, We are using plugin for downloading the files. Please suggest. Thank you for your great plugin. Reply mythili kannan Feb 14, am Hi John, Excellent plugin. Excellent article and great explanation.

Reply eric Jan 28, pm Hello! Fantastic work, the library is pretty solid in Reply Elliot Dec 11, pm Any way to change content type? Reply Bartosz Nov 6, am Hi John, thanks for a great plugin, and great explanation of what is happening under the hood.

Thanks in advance, Bartosz. Reply jip Nov 5, am Looks very promising! Thanks, be blessed j. Thanks a lot in advance. Reply Junes Jul 12, pm Issue has fixed, just add below code in java action is work.

On further digging, I found out that while writing the file to response object it throws following but sometimes it throws following exception: The remote host closed the connection. Flush There seems to be couple of reasons for this as suggested in some forums, user navigates to some other page or closes the browser.

In my case none of the above reasons is true. Please advise me on the best way forward.



0コメント

  • 1000 / 1000