I'm playing around a bit with the FileSystem API.
I've found a lot of examples where you generate a download link and let the user download the file the "browser way".
I would like to know two things:
Is there any way to write the ajax result in the fiddle as a file directly to the disk (without any type of prompt). Like to the user's desktop for example.
Is blob the most suitable format for this?
http://jsfiddle.net/FBGDe/
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
console.log(this.response, typeof this.response);
var img = document.getElementById('img');
var url = window.URL = window.webkitURL;
img.src = url.createObjectURL(this.response);
}
}
xhr.open('GET', 'http://www.newyorker.com/online/blogs/photobooth
/NASAEarth-01.jpg');
xhr.responseType = 'blob';
xhr.send();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…