Skip to content

Instantly share code, notes, and snippets.

@jeffheifetz
Last active December 25, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffheifetz/c1127b4d3e132ffff972 to your computer and use it in GitHub Desktop.
Save jeffheifetz/c1127b4d3e132ffff972 to your computer and use it in GitHub Desktop.
HTML5 FIle Fun
function testFileWriting () {
window.webkitRequestFileSystem(
window.PERSISTENT,
1024*1024,
function(fs) {
console.log("requestFileSystem", arguments);
var xhr = new XMLHttpRequest();
xhr.open('GET', "http://cordova.apache.org/images/cordova_bot.png", true);
xhr.responseType = 'blob';
xhr.onerror = function () {
console.log("xhr.onError", arguments);
};
xhr.onload = function(e) {
console.log("xhr.onLoad", arguments);
if (this.status === 200) {
fs.root.getFile(
"cordova_bot.png",
{create: true},
function (fileEntry) {
console.log("getFile", arguments);
fileEntry.createWriter(function(writer) {
console.log("createWriter", arguments);
writer.onwriteend = function(e) {
console.log("onWriteEnd", arguments);
var img = document.createElement("img");
img.src = blackberry.io.home + "data/webviews/webfs/persistent/local__0/cordova_bot.png";
document.body.appendChild(img);
};
var blob = new Blob([xhr.response], {type: 'image/png'});
writer.write(blob);
});
},
function () {
console.log("getFileError", arguments);
}
);
}
};
xhr.send();
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment