使用 picgo 上传图片
安装 picgo
npm install picgo -g
配置 picgo
配置文件在 ~/.picgo/config.json
,具体配置方法参考 官方文档。
下面展示图床使用腾讯云 COS 的配置示例:
{
"picBed": {
"uploader": "tcyun",
"current": "tcyun",
"tcyun": {
"version": "v5",
"secretId": "************************************",
"secretKey": "********************************",
"bucket": "image-host-1251893006",
"appId": "1251893006",
"area": "ap-chengdu",
"path": "",
"customUrl": "",
"options": ""
}
}
}
使用 super-prefix 插件
很多时候我们希望上传的图片使用的文件名和路径要根据当前时间自动生成,可以使用 picgo 的 super-prefix 插件来做。
- 安装插件:
picgo install super-prefix
- 配置插件(高亮部分):
{
"picBed": {
"uploader": "tcyun",
"current": "tcyun",
"tcyun": {
"version": "v5",
"secretId": "************************************",
"secretKey": "********************************",
"bucket": "image-host-1251893006",
"appId": "1251893006",
"area": "ap-chengdu",
"path": "",
"customUrl": "",
"options": ""
}
},
"picgoPlugins": {
"picgo-plugin-super-prefix": true
},
"picgo-plugin-super-prefix": {
"prefixFormat": "YYYY/MM/DD/",
"fileFormat": "YYYYMMDDHHmmss"
}
}