kennethjiang / js-file-download

MIT License
918 stars 119 forks source link

ReferenceError: Blob is not defined #70

Closed paultrimor closed 3 years ago

paultrimor commented 3 years ago

I get a ReferenceError: Blob is not defined. When I run the code below. I am using NodeJS and Electron.

axios({
        method: 'get',
        url: props.url,
        responseType: 'blob'
    }).then((response) => {
        var filepath = path.resolve(global.sharedObj['outputPath'], props.filename);
        fileDownload(response.data, filepath);
paultrimor commented 3 years ago

Okay, it looks like NodeJS does not support Blob class.

kindrowboat commented 3 years ago

I don't know much about Electron. If you do manage to get either this library or something else working, I'd be happy to either add documentation or support in this library.

justin-hackin commented 3 years ago

@paultrimor you shouldn't need this library if you are performing the code in the electron main context, instead you can use the nodejs fs.writeFile* functions (axios works on the backend too but you have other options like node-fetch) and you also have the benefit of https://www.electronjs.org/docs/api/dialog#dialogshowsavedialogbrowserwindow-options there too

kindrowboat commented 3 years ago

I think @justin-hackin is correct. I'll close the issue.