Skip to content

Instantly share code, notes, and snippets.

@yanfishel
yanfishel / file_download.js
Created April 12, 2017 07:47
JS File Download
var saveFile = function (url, filename) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function () {
var a = document.createElement('a');
a.href = window.URL.createObjectURL(xhr.response); // xhr.response is a blob
a.download = filename; // Set the file name.
a.style.display = 'none';
document.body.appendChild(a);
a.click();
#
# Place it inside << server { } >> Section
#
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your location block(s):
#