【问题标题】:html5 - How to save binary data to html5 file systemhtml5 - 如何将二进制数据保存到 html5 文件系统
【发布时间】:2011-10-30 22:30:49
【问题描述】:

我想将拖放的图像保存到 html5 文件系统中。问题是我不知道如何使用文件 api 将二进制数据写入文件系统。以下是我的部分代码:

var reader = new FileReader();  

reader.onloadend = function(e)
{
      var data = e.target.result;

      // Open File System code (Codes Omitted)
      // Create file           (Codes Omitted)

      fileEntry.createWriter(function(fileWriter)
      {
           // This is the problem, the file is create, something is written to the file
           // because the size is exact same with the dragged file (image). But when i     
           // try to view the file (image), it displays nothing.

           var bb = new WebKitBlobBuilder
           bb.append(data);
           fileWriter.write(bb.getBlob(""));
      }

}

reader.readAsBinaryString(cur_file);

我故意省略了一些代码,例如文件系统和文件创建。我只需要保存二进制数据的帮助。

谢谢。

【问题讨论】:

    标签: html filesystems binary-data


    【解决方案1】:

    我也遇到过类似的问题
    由于您没有在这里解析代码,我假设您以错误的方式阅读图像,
    也许
    您将cur_file 读取为二进制字符串,您的fileReader 是否通过readAsText 方法读取它
    由于文件存储的是binaryString,如果你的fileReader用另一种方式读取它,例如readAsDataURL,那就意味着你再次编码,所以你不能得到正确的答案

    【讨论】:

      猜你喜欢
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-13
      • 2018-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多