-
-
Save jeffheifetz/c1127b4d3e132ffff972 to your computer and use it in GitHub Desktop.
HTML5 FIle Fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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