Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

javascript - Writing file to desktop using HTML5 FileSystem API

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:

  1. 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.

  2. 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please note that Filesystem API is no longer part of the standard's specification, as specified at: http://www.w3.org/TR/file-system-api/

EDIT: Quoting the specification in case the link changes: "File API: Directories and System W3C Working Group Note 24 April 2014

Work on this document has been discontinued and it should not be referenced or used as a basis for implementation."

(This does not relate to the question directly, but it is essential to know not to use the FileSystem API further.)

Another link: http://www.html5rocks.com/en/tutorials/file/filesystem/

"In April 2014, it was announced on public-webapps that the Filesystem API spec should be considered dead. Other browsers have showed little interest in implementing it."


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...