【问题标题】:Are multiple blob's write actions allowed on Google Chrome's FileSystem API?Google Chrome 的 FileSystem API 是否允许多个 blob 的写入操作?
【发布时间】:2014-05-11 20:41:03
【问题描述】:

我正在使用 Google Chrome 16 中的 FileSystem API,但不能多次写入 blob(无需重新打开文件进行追加)。似乎文件在第一次写入后关闭。

例如:

var blob = new WebKitBlobBuilder();
blob.append('one');
fileWriter.write(blob.getBlob('text/plain'));

var blob2 = new WebKitBlobBuilder();
blob2.append('two');
fileWriter.write(blob2.getBlob('text/plain'));

给出 _Uncaught Error: INVALID_STATE_ERR: DOM File Exception 7_

W3 文档提到了FileWriter“这个接口扩展了 FileSaver 接口,允许多个写入操作,而不仅仅是保存单个 Blob。”

【问题讨论】:

    标签: javascript html api google-chrome filesystems


    【解决方案1】:

    根据规范,您不能在编写器忙于编写时使用

    write

    1. 如果 readyStateWRITING,则抛出带有错误代码 INVALID_STATE_ERRFileException 并终止这一系列步骤。

    由于编写器是异步的,因此您必须使用回调等待:

    // write first blob
    
    fileWriter.onwriteend = function() {
      // write second blob
    };
    

    【讨论】:

    • 谢谢,这是我的错。我试图在事件提出之前写。
    猜你喜欢
    • 1970-01-01
    • 2019-01-25
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2020-03-25
    相关资源
    最近更新 更多