简体   繁体   中英

Replacement for fileEntry.toURL() in Chrome Packaged Apps

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM