Skip to content

Commit dc2cf9b

Browse files
authored
Merge pull request kennethjiang#7 from wuppious/master
Allow to specify mime type
2 parents 845f31a + a789750 commit dc2cf9b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

file-download.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var React = require('react');
22

3-
module.exports = function(data, filename) {
4-
var blob = new Blob([data], {type: 'text/csv'});
3+
module.exports = function(data, filename, mime) {
4+
var blob = new Blob([data], {type: mime || 'application/octet-stream'});
55
if (typeof window.navigator.msSaveBlob !== 'undefined') {
66
// IE workaround for "HTML7007: One or more blob URLs were
77
// revoked by closing the blob for which they were created.
@@ -10,9 +10,9 @@ module.exports = function(data, filename) {
1010
window.navigator.msSaveBlob(blob, filename);
1111
}
1212
else {
13-
var csvURL = window.URL.createObjectURL(blob);
13+
var blobURL = window.URL.createObjectURL(blob);
1414
var tempLink = document.createElement('a');
15-
tempLink.href = csvURL;
15+
tempLink.href = blobURL;
1616
tempLink.setAttribute('download', filename);
1717
tempLink.setAttribute('target', '_blank');
1818
document.body.appendChild(tempLink);

0 commit comments

Comments
 (0)