johnculviner / jquery.fileDownload

jQuery File Download is a cross server platform compatible jQuery plugin that allows for an Ajax-like file download experience that isn’t normally possible using the web.
http://johnculviner.com/post/2012/03/22/Ajax-like-feature-rich-file-downloads-with-jQuery-File-Download.aspx
MIT License
1.07k stars 977 forks source link

Promises: fail() called but done() not #104

Open wimrijnders opened 9 years ago

wimrijnders commented 9 years ago

Hi there,

I added jQuery.fileDownload to my code yesterday. While it works, there are two issues which I encountered, one of them is this. I noticed that there are several related issues already present, but not quite what I encountered. So I'll stick out my neck and add a new one.

In stripped form, the javascript code is use is:

$.fileDownload(action, {
    httpMethod: "POST",
    data: fields
})
.done(function () {
    alert('Download succeeded. Actually never called!');
})
.fail(function (data) {
    alert('Failed, but at least I can tell you about it.');
});

done() is never called, even on complete success. fail() IS called however, which is the saving grace, since it's exactly what I needed. Nevertheless, it sort of feels incomplete.

This is on linux, using browser Chromium Version 44.0.2403.89 (64-bit)

kachkaev commented 8 years ago

I just had the same issue in a different browser, but after setting the cookie on the server, it was resolved. It is important to make sure that the cookie is not httponly and can be visible by the js too.

wimrijnders commented 8 years ago

Thanks for the tip. I'll double check if the cookie is set ok.

wimrijnders commented 8 years ago

I took the time to rigorously examine this issue. To be honest, I found several things wrong on the server side. After building in some workarounds for my stupid ignorance, I still couldn't get it to work.

I also tried the, let's say, 'traditional' method of using fileDownload, i.e. like this:

$.fileDownload(url, {
  successCallback: function(url) {
    alert('File download a success!');
  },
  failCallback: function(responseHtml, url) {
    alert($(responseHtml).text());
  }
});

With the same lack of success. The response header currently returned is:

Connection:keep-alive
Content-Disposition:attachment; filename="zipfile.zip"
Content-Length:40032
Content-Type:Application/zip
Last-Modified:Sat, 07 Nov 2015 07:57:41 GMT
Server:thin
Set-Cookie:fileDownload=true; path=/path/to/my/zipfile.zip
X-Content-Type-Options:nosniff

Is there anything suspicious in this header?

wimrijnders commented 8 years ago

Let me define 'lack of success' in previous: the download proceeds fine, just the alert saying that the download succeeded is never shown.

johnculviner commented 8 years ago

not seeing anything ovious. Make sure the cookie is visible to javascript in your browser too by doing document.cookies (it doesn't look like its HTTP ONLY) though...

medaamarnadh commented 8 years ago

What is the cookie name and value we have to set on server . Can any one tell the example

johnculviner commented 8 years ago

The front page read me of the plugin says what to do in H1 text

On Apr 14, 2016, at 9:23 AM, medaamarnadh notifications@github.com wrote:

What is the cookie name and value we have to set on server . Can any one tell the example

— You are receiving this because you commented. Reply to this email directly or view it on GitHub

micky2be commented 6 years ago

Why does the server need to set the cookie???? I'm downloading from S3. There is no server here.

joshuapinter commented 5 years ago

The front page read me of the plugin says what to do in H1 text

On Apr 14, 2016, at 9:23 AM, medaamarnadh notifications@github.com wrote: What is the cookie name and value we have to set on server . Can any one tell the example — You are receiving this because you commented. Reply to this email directly or view it on GitHub

No it doesn't. It says this in H1 text:

Note - You must also write a cookie in conjunction with using this plugin as mentioned in the orignal post:

Not being ungrateful but the README of the code repository should probably be the source of truth and where the instructions are, not linking to an outdated blog post. If this is so important with the usage of this plugin, it should be part of the Usage/Installation section and not an afterthought.

johnculviner commented 5 years ago

@joshuapinter I'm sorry bro you right it's in the paragraph body right below the H1 text. I look forward to you sending me a pull request fixing any of your perceived issues with this plugin otherwise I'll try to get around to making those changes sometime here.

joshuapinter commented 5 years ago

@johnculviner Again, no disrespect. I'll submit a PR to make things a bit more clear. Thanks again for your plugin and all your hard work. 👍

ZizzyZizzy commented 3 years ago

I pulled my hair out over this issue showing up in prod but not dev.

It turns out an apache setting for security/compliance was the culprit:

# Enable secure cookies and prevent click-jacking
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure

change it to this:

# Enable secure cookies and prevent click-jacking
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
# Except for fileDownload, otherwise it breaks jqueryfileDownload
Header edit Set-Cookie "(fileDownload=.*)(;HttpOnly;Secure)" "$1"