When I try to store a blob (retrieved via an XMLHttpRequest
GET
request, Safari on iOS 8.4 throws the error:
DataCloneError: DOM IDBDatabase Exception 25: The data being stored could
not be cloned by the internal structured cloning algorithm
This happen with my code and also this example: http://robnyman.github.io/html5demos/indexeddb/
This is the line that cause my code (and the above example) to fail:
//This throws the error
var put = transaction.objectStore("elephants").put(blob, "image");
Is there a fix for this? Does the blob need to be base64 encoded first (like you had to do with WebSQL)?
My CODE (works in Desktop Chrome/Firefox and Chrome/Firefox on Android):
var xhr = new XMLHttpRequest();
var blob;
//Get the Video
xhr.open( "GET", "test.mp4", true );
//Set as blob
xhr.responseType = "blob";
//Listen for blob
xhr.addEventListener("load", function () {
if (xhr.status === 200) {
blob = xhr.response;
//Start transaction
var transaction = db.transaction(["Videos"], "readwrite");
//IT FAILS HERE
var put = transaction.objectStore("Videos").put(blob, "savedvideo");
}
else {
console.log("ERROR: Unable to download video." );
}
}, false);
xhr.send();