chrome扩展程序如何将图像下载到扩展程序根目录 [英] How chrome extension download images to extension root directory

查看:77
本文介绍了chrome扩展程序如何将图像下载到扩展程序根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次进行Chrome扩展程序.

I'm making a chrome extension for the first time.

对于我的扩展程序,我希望它可以自动将图像下载到其扩展程序文件夹中.例如,如果扩展名文件夹为/xxxx/abc/,我希望它可以将图像下载到/xxxx/abc/image/.

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.

我发现扩展名可以做到.叫做动量.它可以将图像下载到/xxxx/<extension root dir>/backgrounds/.

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!

推荐答案

不,您不能.扩展名只能以只读方式访问自己的文件.

No, you can't. An extension has only read-only access to own files.

相反,您可以下载到虚拟HTML5文件系统并使用其中的文件.请参见本教程-红色大警告表示没有其他浏览器使用此技术,但是Chrome可以.

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.

您可能需要声明"unlimitedStorage"权限,以确保您有足够的空间来存储文件.

You may want to declare "unlimitedStorage" permission to make sure you have the space to store the files.

这是一个虚拟文件系统,实际上不是那些可以在磁盘上打开的文件.如果以后需要将文件提供给用户,则可以使用chrome.downloads将文件写入下载文件夹,但这是只写"的,以后就不能访问内容.

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.

这篇关于chrome扩展程序如何将图像下载到扩展程序根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆