Skip to content Skip to sidebar Skip to footer

Merging Multiple Parts Of A File In Cordova

Within my Cordova app, I am downloading arbitrary files like images or video files. This is done with the Cordova file-transfer plugin and the 'Range' Header, because I need to dow

Solution 1:

you can build a blob from other blobs, like the ones you use FileReader on now. (File()s are Blobs)

// put three blobs into a fourth:var b=newBlob([newBlob(["hello"]), newBlob([" "]), newBlob(["world"])]);

// verify the blob has the data we expect:var fr=newFileReader();
fr.onload=function(){alert(this.result);};
fr.readAsBinaryString(b);  // shows: "hello world"

the binaryString flavor is used here to show how these low-order strings stack up, but the actual new blob instance should have all the orig (arbitrary) bytes from the original blobs, even if they aren't composed of simple strings...

Solution 2:

Using readAsArrayBuffer() instead of readAsBinaryString() did the trick!

So instead of:

myFileReader.readAsBinaryString(theActualFile);

I did:

myFileReader.readAsBinaryArray(theActualFile);

And the resulting image file is usable.

Post a Comment for "Merging Multiple Parts Of A File In Cordova"