简体   繁体   English

如何将文件下载到Chrome扩展程序的扩展程序文件夹中?

[英]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. 我想使用chrome.extension.getURL加载下载的本地文件。 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. 我尝试了chrome.downloads.download ,但这默认情况下会保存到downloads文件夹中。

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 . 您可以通过XMLHttpRequest / $.get下载文件,将其作为字符串/ blob存储在WebSQLIndexedDBchrome.storage.local等本地存储中,然后将其作为数据URI添加到网页中。

You can't save the file anywhere except under the downloads directory, see chrome.downloads API : 除了在downloads目录下,您无法将文件保存在其他任何地方,请参阅chrome.downloads API

  • chrome.downloads.download : chrome.downloads.download

    Absolute paths, empty paths, and paths containing back-references ".." will cause an error. 绝对路径,空路径以及包含反向引用“ ..”的路径都将导致错误。 onDeterminingFilename allows suggesting a filename [...] onDeterminingFilename允许建议文件名[...]

  • chrome.downloads.onDeterminingFilename : chrome.downloads.onDeterminingFilename

    a path relative to the user's default Downloads directory, possibly containing subdirectories. 相对于用户默认的Downloads目录的路径,可能包含子目录。 Absolute paths, empty paths, and paths containing back-references ".." will be ignored. 绝对路径,空路径和包含反向引用“ ..”的路径将被忽略。

There are no other APIs to download a file. 没有其他API可以下载文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM