How chrome extension download images to extension root directory

六月ゝ 毕业季﹏ 提交于 2019-12-24 17:53:07

问题


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

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