I hope this will help.
I had the same download issue on Safari with my NodeJS App. This is not a real issue, nor an issue with Safari. Safari was in my case just doing it job.
Explaination
Step #1: When you have an HTTP link (<a></a>
), and you click on it, what is going to happen is a regular HTTP GET
request sent to your server (NodeJS, Nginx or Apache).
Step #2: Then, your backend will serve the Response with your attachment
. I will assume that you have done everything properly regarding the headers; content-type
, content-disposition
, content-content-length
.
Step #3: The browser then receives the response and treat it how it should: I asked for a HTTP Request, I am expecting a HTTP Response.
The thing in NodeJS, is that if you do not send a response.end()
you will get a Failed to load resource: Frame load interrupted
. At the same time, if you do send a response.end()
with or without content, it will replace the content of the page you are triggered the request from.
Solution
What I have found that worked for me was to send in Step #1
a XML HTTP GET
request, meaning AJAX
request, instead of the regular HTTP GET
. This way, the action is being treated in background as a XMLRequest: {'X-Requested-With': 'XMLHttpRequest'}
.
To implement this, you can do it by hand or use a framework like jQuery.