问题
I'm making a chrome extension for the first time.
For my extension, I want it can automatically download images to its extension folder. For example, if the extension folder is /xxxx/abc/
, I want it can download images to /xxxx/abc/image/
.
To make it, I don't know how to write file/ download image to this directory. I don't want users notice this.
I found an extension can make it. It's called Momentum. It can download images to /xxxx/<extension root dir>/backgrounds/
.
Can anybody tell me what technique do I need? Thanks a lot!
回答1:
No, you can't. An extension has only read-only access to own files.
Instead, you can download to a virtual HTML5 filesystem and use files from it. See this tutorial - the big red warning means no other browser uses this technology, but Chrome does.
You may want to declare "unlimitedStorage"
permission to make sure you have the space to store the files.
This being a virtual filesystem, those won't actually be files you can open on your disk. If you need to give files to the user afterward, you can use chrome.downloads
to write them to the downloads folder, but that's "write-only", you can't access the contents afterwards.
来源:https://stackoverflow.com/questions/30130260/how-chrome-extension-download-images-to-extension-root-directory