Tencent COS provider for Strapi
# using yarn
yarn add strapi-provider-upload-tencent-cloud-storage
# using npm
npm install strapi-provider-upload-tencent-cloud-storage --save
provider
defines the name of the providerproviderOptions
is passed down during the construction of the provider. It contains the following properties:
upload
method. You can find the complete list of options here.See the documentation about using a provider for information on installing and using a provider. To understand how environment variables are used in Strapi, please refer to the documentation about environment variables.
./config/plugins.js
or ./config/plugins.ts
for TypeScript projects:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: "strapi-provider-upload-tencent-cloud-storage",
providerOptions: {
SecretId: env("COS_SECRET_ID"),
SecretKey: env("COS_SECRET_KEY"),
Region: env("COS_REGION"),
Bucket: env("COS_BUCKET"),
},
},
},
// ...
});
If your bucket is configured to be private, you will need to set the ACL
option to private
in the params
object. This will ensure file URLs are signed.
Note: If you are using a CDN, the URLs will not be signed.
You can also define the expiration time of the signed URL by setting the Expires
option in the providerOptions
object. The default value is 360 seconds (6 minutes).
./config/plugins.js
or ./config/plugins.ts
for TypeScript projects:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: "strapi-provider-upload-tencent-cloud-storage",
providerOptions: {
SecretId: env("COS_SECRET_ID"),
SecretKey: env("COS_SECRET_KEY"),
Region: env("COS_REGION"),
Bucket: env("COS_BUCKET"),
ACL: "private", // <= set ACL to private
},
},
},
// ...
});
Due to the default settings in the Strapi Security Middleware you will need to modify the contentSecurityPolicy
settings to properly see thumbnail previews in the Media Library. You should replace strapi::security
string with the object bellow instead as explained in the middleware configuration documentation.
./config/middlewares.js
or ./config/middlewares.ts
for TypeScript projects:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module.exports = [
// ...
{
name: "strapi::security",
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
"connect-src": ["'self'", "https:"],
"img-src": [
"'self'",
"data:",
"blob:",
"market-assets.strapi.io",
"yourBucketName.cos.yourRegion.myqcloud.com",
],
"media-src": [
"'self'",
"data:",
"blob:",
"market-assets.strapi.io",
"yourBucketName.cos.yourRegion.myqcloud.com",
],
upgradeInsecureRequests: null,
},
},
},
},
// ...
];
./config/plugins.js
or ./config/plugins.ts
for TypeScript projects:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: "strapi-provider-upload-tencent-cloud-storage",
providerOptions: {
CDNDomain: "example-cdn-domain.com", // <= CDN Accelerated Domain
SecretId: env("COS_SECRET_ID"),
SecretKey: env("COS_SECRET_KEY"),
Region: env("COS_REGION"),
Bucket: env("COS_BUCKET"),
},
},
},
// ...
});
Feel free to fork and make a Pull Request to this plugin project. All the input is warmly welcome!
npm install strapi-provider-upload-tencent-cloud-storage
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.