替换Chrome Packaged Apps中的fileEntry.toURL() [英] Replacement for fileEntry.toURL() in Chrome Packaged Apps
问题描述
我使用 HTML5 FileSystem API 在 Chrome打包应用程序中写入日志文件。我希望用户能够下载此文件,所以我尝试了以下内容:
fs.root.getFile ('log.txt',{create:false},function(fileEntry){
var url = fileEntry.toURL();
//对文件url做
});
但这并没有什么帮助,因为URL类似于 filesystem: chrome-extension://eekedjcagggbfigdmifkmhkjbhiklnpj/temporary/log.txt
并且无法在某处打开它。
您会推荐哪种技术在Packaged App中下载FileSystem API文件?
编辑:在阅读Ben Well的 answer ,我意识到我将不得不澄清我想要的东西。对我来说,如果有一种技术不会暗示加载HTML5文件系统API文件内容,从它构建一个blob并将其写入到用户选择的路径中,那对我来说似乎特别好。 chrome.fileSystem API 。
I'm using the HTML5 FileSystem API in a Chrome Packaged App to write to a log file. I want the user to be able to download this file, so I tried something along the lines of:
fs.root.getFile('log.txt', {create: false}, function(fileEntry) {
var url = fileEntry.toURL();
// do something with the file url
});
This doesn't help though, because the URL is something like filesystem:chrome-extension://eekedjcagggbfigdmifkmhkjbhiklnpj/temporary/log.txt
and it's not possible to open it somewhere.
What technique would you recommend to make a FileSystem API file in a Packaged App downloadable?
Edit: After reading through Ben Well's answer below, I realized that I'll have to clarify even more what I want. It would seem especially nice to me if there would be a technique that doesn't imply loading the HTML5 Filesystem API file contents, building a blob from it and writing that to a user-chosen path with chrome.fileSystem API.
Have you tried using chrome.fileSystem.chooseEntry? This API lets your app save files to the user's hard disk, wherever they want, letting your program have a Save As kind of command. This is a bit different to a download link, but is also more in harmony with V2 apps being like native apps.
chrome.fileSystem pops up a dialog asking the user to choose a location for a file. If you use the options for saving files, this returns you a file entry that has permissions to write to the location chosen by the user. The user can also create new files when you use these options.
这篇关于替换Chrome Packaged Apps中的fileEntry.toURL()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!