fileSystem API—其中是保存目录

fileSystem API - Where is the save directory?

本文关键字:保存 API fileSystem      更新时间:2023-09-26

我正在尝试使用fileSystemapi保存一个文件。

下面的代码似乎运行良好。

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

如果它在macos中,它应该位于以下目录中??

/用户/USERNAME/库/应用程序支持/谷歌/Chrome/默认/文件系统/

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

请帮帮我!!

谢谢!

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

这是一个虚拟文件系统。虽然文件系统容器当然在驱动器上的某个地方,但它实际上可能并不是由文件夹中某个地方的文件来表示的。请参阅此问题。

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


你的问题被模糊地标记了;如果是Chrome应用程序,则可以使用chrome.fileSystem来处理真实文件。