【问题标题】:Where is the file sandbox for a Chrome app?Chrome 应用的文件沙盒在哪里?
【发布时间】:2014-01-19 05:00:55
【问题描述】:

我正在开发一个能够处理文件的 chrome 应用程序。我需要将这些文件复制到应用程序中,我相信它会将其存储在应用程序的沙箱中。

但是这些文件在哪里,比如在我的磁盘上?

这是我访问文件系统的地方:

fs = null

oneGig = Math.pow 2, 30 # 1GB
window.webkitRequestFileSystem window.PERSISTENT, oneGig,
  (_fs) -> # on fs init
    fs = _fs
    console.log fs.root.fullPath #=> "/" obviously not right

  (e) -> # on fs error
    console.log e

接下来是这段代码来实际写入文件。

fs.root.getFile songObj.md5, create: true, (fileEntry) ->
  fileEntry.createWriter (fileWriter) ->
    fileWriter.onwriteend = (e) ->
      console.log 'Song file saved!', fileEntry, e

      # Where the hell on disk is my file now?

    fileWriter.onerror    = (e) ->
      console.log 'fileWriter.onerror', e

    fileWriter.write songObj.blob

  , (e) -> console.log 'fileEntry.createWriter error', e
, (e) -> console.log 'fs.root.getFile error', e

我在文件处理中遇到了一些错误,我希望能够轻松检查正在发生的事情,并在必要时进行清理。而且我似乎在文档中找不到它说文件的任何地方。这尤其令人沮丧,因为几天后我回到应用程序后文件就消失了。

【问题讨论】:

  • 沙箱被混淆了。这些文件只能通过 API 以编程方式获得。这似乎不是规范 (dev.w3.org/2006/webapi/FileAPI) 的要求,但从安全角度来看是有道理的。当然,数据确实存在于您的本地磁盘上,但格式很奇怪。修复代码比找出格式更容易。您为什么不提出一个直接解决文件消失问题的新问题?
  • 另外,请查看stackoverflow.com/a/11497638/65977,它可以让您从 Chrome DevTools 中检查文件系统。

标签: javascript coffeescript google-chrome-app html5-filesystem


【解决方案1】:

它们进入一个不易检查的“沙盒”。您可能希望使用新的 chrome.fileSystem chooseEntry 函数 (http://developer.chrome.com/apps/fileSystem.html) 和“directory”选项以及“retainEntry”来访问写入计算机上的普通目录,以便您可以查看文件和清除浏览器缓存等时不要清除它们。

【讨论】:

    【解决方案2】:

    因此,在 HTML5 文件系统 API 方面,我不完全确定 Chrome 应用程序与普通网页有何不同。

    但我可以说,在 Windows 7 上使用 Chrome 的持久存储就在这里:

    C:\Users\{user}\AppData\Local\Google\Chrome\User Data\Default\File System\
    

    如果您想通过 Chrome 在其他操作系统上了解它的存储位置,请参阅this_post

    注意,目录名称很奇怪,尽管底层文件内容和大小完全相同,所以如果您浏览文件并在文本编辑器中打开,您将能够看到您的原始内容将文件复制到持久网络应用程序空间之前。

    【讨论】:

      猜你喜欢
      • 2014-11-29
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      • 1970-01-01
      • 2010-12-08
      相关资源
      最近更新 更多