问题
How can I enumerate files under a static folder (such as images where all the static images used by my app are stored) while developing a chrome app?
What I have tried:
- looked at these links 1, 2. i am not trying to read from local or user storage. i want to read from static storage. static storage are the folders where an app stores its static contents - assets like images, css, js etc.
- looked at this link. but my app needs to be able to enumerate all files under a static folder without prompting the user for any action/permission.
i will give an example of why this is useful. imagine i want to release an app using which users can read my poems. i want a static folder where i save poems i write. then as i write new poems, these poems should then be made available automatically without having to do any code changes. further i was able to do this on android without any user prompt whatsoever so expect chrome platform should also support this - there cannot be any security excuses.
回答1:
If you are looking to enumerate app's own files, it's possible via chrome.runtime.getPackageDirectoryEntry.
It returns a DirectoryEntry
for the root of your app that you can navigate and iterate through.
See this question: How do I get a list of filenames in a subfolder of a Chrome extension?
回答2:
You can't. The user will have to choose some parent folder with chrome.fileSystem.chooseEntry at some point. However, you can arrange things so this is done only once when the app is first installed, and then save the FileEntry using the retained-entry API.
来源:https://stackoverflow.com/questions/24718047/chrome-app-how-to-enumerate-files-under-a-static-folder