Skip to content

Commit

Permalink
use ms-specific api for saving Blobs instead of using the File constr…
Browse files Browse the repository at this point in the history
…uctor (#4376)
  • Loading branch information
meirish authored Apr 17, 2018
1 parent a4804c5 commit fc82415
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions ui/app/components/download-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,37 @@ export default Ember.Component.extend({
return `${this.get('filename')}-${new Date().toISOString()}.${this.get('extension')}`;
}),

href: computed('data', 'mime', 'stringify', function() {
fileLike: computed('data', 'mime', 'strigify', 'download', function() {

This comment has been minimized.

Copy link
@kalafut

kalafut Apr 17, 2018

Contributor

strigify ?

This comment has been minimized.

Copy link
@meirish

meirish Apr 17, 2018

Author Contributor

🤦‍♂️ left out an n - thanks for catching that!

let file;
let data = this.get('data');
const mime = this.get('mime');
let filename = this.get('download');
let mime = this.get('mime');
if (this.get('stringify')) {
data = JSON.stringify(data, null, 2);
}
if (window.navigator.msSaveOrOpenBlob) {
file = new Blob([data], { type: mime });
file.name = filename;
} else {
file = new File([data], filename, { type: mime });
}
return file;
}),

const file = new File([data], { type: mime });
return window.URL.createObjectURL(file);
href: computed('fileLike', function() {
return window.URL.createObjectURL(this.get('fileLike'));
}),

click(event) {
if (!window.navigator.msSaveOrOpenBlob) {
return;
}
event.preventDefault();
let file = this.get('fileLike');
//lol whyyyy
window.navigator.msSaveOrOpenBlob(file, file.name);
},

actionText: 'Download',
data: null,
filename: null,
Expand Down

0 comments on commit fc82415

Please sign in to comment.