eligrey / Blob.js

An HTML5 Blob implementation
Other
1.15k stars 605 forks source link

How do you use Blob.js? #57

Closed JCLaHoot closed 6 years ago

JCLaHoot commented 6 years ago

I'm having trouble using Blob.js...

when I run the following code, everything works fine:

        //downloads the puzzle as a JSON file
        let blob = new Blob([JSON.stringify(puzzle)], {type: "application/json;charset=utf-8"});
        FileSaver.saveAs(blob, `puzzle-${this.state.puzzleName}.json`);

but if I do

        //downloads the puzzle as a JSON file
        let blob = new BlobJS([JSON.stringify(puzzle)], {type: "application/json;charset=utf-8"});
        FileSaver.saveAs(blob, `puzzle-${this.state.puzzleName}.json`);

my webapp crashes and I get the following error, despite the fact that I've imported Blob.js

TypeError: WEBPACK_IMPORTED_MODULE_2_blobjsdefault.a is not a constructor

How am I supposed to use Blob.js? I see that there's lots of links to the Blob documentation in this repo, but obviously I'm missing something because using it like the native Blob doesn't do the same thing...

liaodiv commented 6 years ago

you just use like this: import 'blob.js' const blob = new Blob(......); //Blob import as a global variables