【问题标题】:fileSystem API - Where is the save directory?fileSystem API - 保存目录在哪里?
【发布时间】:2014-09-02 09:36:47
【问题描述】:

我正在尝试使用 fileSystem api 保存文件。

看来下面这段代码运行良好。

但是,我找不到保存的文件的位置。

如果是mac os,应该在下面的目录下??

/Users/USERNAME/Library/Application Support/Google/Chrome/Default/File System/

我的项目快完成了。我所要做的就是实现将文件保存在本地驱动器中的功能!

请帮帮我!!

谢谢!

function writeToLocal(filename, content) {

    function errorCallback(e) {
        alert("Error: " + e.name);
    }

function fsCallback(fs) {
    fs.root.getFile(filename, {create: true}, function(fileEntry) {
        fileEntry.createWriter(function(fileWriter) {

            fileWriter.onwriteend = function(e) {
                alert("Success! : " + fileEntry.fullPath);
            };

            fileWriter.onerror = function(e) {
                alert("Failed: " + e);
            };

            var output = new Blob([content], {type: "text/plain"});
            fileWriter.write(output);
        }, errorCallback);
    }, errorCallback);
}

webkitStorageInfo.requestQuota(PERSISTENT, 1024,
    webkitRequestFileSystem(PERSISTENT, 1024, fsCallback, errorCallback),
errorCallback);
}

writeToLocal("test.txt", "hello world\n");

【问题讨论】:

    标签: javascript html google-chrome-extension google-chrome-app html5-filesystem


    【解决方案1】:

    这是一个虚拟文件系统。尽管文件系统容器当然位于驱动器上的某个位置,但它实际上可能并不代表您的文件位于文件夹中的某个位置。见this question

    关于如何从这个文件系统中取出数据,可以使用chrome.downloads API 导出文件。


    您的问题被含糊地标记了;如果它是 Chrome App,您可以使用 chrome.fileSystem 来处理真实文件。

    【讨论】:

    • 哦,我明白了。实际上,我正在开发一个 chrome 扩展。但似乎我不能将 chrome.fileSystem 用于 chrome 扩展。我可能会将其转换为 chrome 应用程序而不是 chrome 扩展程序。但是,我仍然想知道在哪里可以找到保存的文件...它应该位于您链接到的页面上显示的同一目录中。
    • 可能,但如果是,则不会命名为test.txt
    • 按照设计,您找不到保存的文件。它被混淆了,使得将其用作真实文件是不切实际的。否则,此 API 可能会成为将坏文件放在用户计算机上的载体。
    • @W3Q 为了解释我对chrome.downloads的评论,如果你需要导出一个文件,你可以在你的下载文件夹(或它的子文件夹)中放置一个真实的文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 2011-08-28
    • 1970-01-01
    相关资源
    最近更新 更多