Chrome app create and write to file

狂风中的少年 提交于 2019-12-11 09:54:25

问题


I am attempting to use chrome.apps for a program that needs to write multiple separate log files of data. The user then needs to be able to access these these log files outside of the app in their file system for post processing.

This will need to be done many times so minimum to no user interaction would be desired for file generation. While this is simple in any native program code, I've been finding this very difficult to do with chrome apps. E.g. can I use chrome apps to create "log_file.txt" & "log_file2.txt" without user interaction? Is there any way I can have the user just specify a directory then from my app, I would be able to create multiple files within that directory without user interaction? I've tried to do this in code but I need "entry" handles for the chrome.filesystem. The "getEntry" method requires an "entry" so it seems impossible to create new "entry"s such that I can write to new files. Any ideas would be appreciated!


回答1:


Is there any way I can have the user just specify a directory then from my app, I would be able to create multiple files within that directory without user interaction?

Yes. You need to request a directory with

chrome.fileSystem.chooseEntry({type: "openDirectory"}, /*...*/);

As long as you have the permissions

{"fileSystem": ["write", "retainEntries", "directory"]} 

you will be able to create files in that directory, and "retain" (save) the directory entry for later reuse without asking the user again. Creating the files once you have a DirectoryEntry should be similar to this.

But that minimum of interaction (asking for the folder initially) is required.



来源:https://stackoverflow.com/questions/35209773/chrome-app-create-and-write-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!