使用HTML5 FileSystem API将文件写入桌面 [英] Writing file to desktop using HTML5 FileSystem API

查看:123
本文介绍了使用HTML5 FileSystem API将文件写入桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩 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".

我想知道两件事:


  1. 有吗以任何方式将ajax结果作为文件直接写入磁盘(没有任何类型的提示)。比如用户的桌面。例如。

  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.

blob是最合适的格式吗?

Is blob the most suitable format for this?

http://jsfiddle.net/FBGDe/ p>

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();      


推荐答案

不幸的是,目前无法写入常规文件(尽管接受的答案使用HTML5和JavaScript修改本地文件)。

Unfortunately, writing to regular files is not currently possible (despite the accepted answer Modifying Local Files Using HTML5 and JavaScript).

您只能写入沙盒文件系统。

You can only write to the sandboxed filesystem.

仅供参考,您可以在Chrome打包应用中执行此操作: http://developer.chrome.com/apps/fileSystem.html 但即便如此用户至少必须首先选择文件。写入任何文件将是一个严重的安全漏洞。

FYI, you can do this in a Chrome Packaged App: http://developer.chrome.com/apps/fileSystem.html But even then the user must at least choose the file first. Writing to any file would be a serious security hole.

你真的想解决什么问题?

What problem are you really trying to solve?

这篇关于使用HTML5 FileSystem API将文件写入桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆