Reputation: 1014
I started using filesaver.js today.I have created the following function:
function saving(){
var blob = new Blob(final_transformation, {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");
}
but when i call that function i get"Failed to construct 'Blob': The 1st argument provided is either null, or an invalid Array object. " Any ideas?
Upvotes: 10
Views: 28754
Reputation: 13354
I was getting the same error.
See the Blob constructor documentation at https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob:
var aBlob = new Blob( array[, options]);
array
is anArray
ofArrayBuffer
,ArrayBufferView
,Blob
,DOMString
objects, or a mix of any of such objects, that will be put inside theBlob
.
So the first parameter to new Blob
is pretty specific - it can only be an array that contains objects of several specific types. A regular string was not working for me, but this works:
> new Blob( [ new TextEncoder().encode( 'some text' ) ], { type: 'text/plain' } )
< Blob {size: 9, type: "text/plain"}
Upvotes: 4
Reputation: 78046
Since you won't tell us what final_transformation
is, we have to guess with no context. Try this :
function saving(){
var blob = new Blob([final_transformation], {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");
}
Upvotes: 26