【发布时间】: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