'Direct file download code not work in shopify
This here is js file download code which works for other servers but does not work on shopify.
url: 'https://cdn.shopify.com/s/files/1/0518/1269/6219/files/sample-3s.mp3',
method: 'GET',
async:true,
crossDomain:true,
headers:{'Content-Type':'audio/mpeg','X-Requested-With':'XMLHttpRequest'},
processData: false,
dataType: 'binary',
xhrFields: {
responseType: 'blob'
},
success: function (data) {
var a = document.createElement('a');
var url = window.URL.createObjectURL(data);
a.href = url;
a.download = 'sample-3s.mp3';
document.body.append(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
}
});
});```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
