jquery.fileDownload icon indicating copy to clipboard operation
jquery.fileDownload copied to clipboard

Promises: fail() called but done() not

Open wimrijnders opened this issue 8 years ago • 12 comments

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)

wimrijnders avatar Sep 01 '15 07:09 wimrijnders

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.

kachkaev avatar Oct 21 '15 19:10 kachkaev

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

wimrijnders avatar Oct 21 '15 19:10 wimrijnders

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 avatar Nov 23 '15 17:11 wimrijnders

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

wimrijnders avatar Nov 23 '15 17:11 wimrijnders

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...

johnculviner avatar Nov 26 '15 15:11 johnculviner

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

medaamarnadh avatar Apr 14 '16 14:04 medaamarnadh

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

On Apr 14, 2016, at 9:23 AM, medaamarnadh [email protected] 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

johnculviner avatar Apr 14 '16 14:04 johnculviner

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

micky2be avatar Sep 19 '18 08:09 micky2be

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

On Apr 14, 2016, at 9:23 AM, medaamarnadh [email protected] 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.

joshuapinter avatar Jan 07 '19 01:01 joshuapinter

@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.

johnculviner avatar Jan 18 '19 02:01 johnculviner

@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. 👍

joshuapinter avatar Jan 18 '19 07:01 joshuapinter

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"

ZizzyZizzy avatar Nov 02 '20 02:11 ZizzyZizzy