替换Chrome Packaged Apps中的fileEntry.toURL() [英] Replacement for fileEntry.toURL() in Chrome Packaged Apps

查看:100
本文介绍了替换Chrome Packaged Apps中的fileEntry.toURL()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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

解决方案

您是否尝试过使用 chrome.fileSystem.chooseEntry ?这个API可让您的应用程序将文件保存到用户的硬盘上,无论他们想要什么,让您的程序拥有另存为类型的命令。这与下载链接有所不同,但与V2应用程序更像是本机应用程序。在这种情况下,chrome.file系统弹出一个对话框,询问用户为文件选择一个位置。如果使用选项来保存文件,则会返回一个文件条目,该文件条目有权写入用户选择的位置。用户也可以在使用这些选项时创建新文件。


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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆