简体   繁体   中英

How do I download a file to the extension folder in a Chrome extension?

I want to use chrome.extension.getURL to load a local file that was downloaded. Since this can only access files in the extensions folder, how do I save files to the extensions folder?

I tried chrome.downloads.download , but this saves to the downloads folder by default.

You can download the file via XMLHttpRequest / $.get , store it as a string/blob in some local storage like WebSQL , IndexedDB or chrome.storage.local , then add it to a webpage as a data URI .

You can't save the file anywhere except under the downloads directory, see chrome.downloads API :

  • chrome.downloads.download :

    Absolute paths, empty paths, and paths containing back-references ".." will cause an error. onDeterminingFilename allows suggesting a filename [...]

  • chrome.downloads.onDeterminingFilename :

    a path relative to the user's default Downloads directory, possibly containing subdirectories. Absolute paths, empty paths, and paths containing back-references ".." will be ignored.

There are no other APIs to download a file.

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