• Product

  • Solutions

  • Developers

  • Docs

  • Pricing

  • Cloud

Search icon
Strapi plugin logo for Tencent Cloud Storage

Tencent Cloud Storage

Tencent COS provider for Strapi

strapi-provider-upload-tencent-cloud-storage

Resources

Links

Installation

# using yarn
yarn add strapi-provider-upload-tencent-cloud-storage

# using npm
npm install strapi-provider-upload-tencent-cloud-storage --save

Configuration

  • provider defines the name of the provider
  • providerOptions is passed down during the construction of the provider. It contains the following properties:

    • SecretId: Tencent Cloud API SecretId
    • SecretKey: Tencent Cloud API SecretKey
    • Region: Tencent Cloud API Region
    • Bucket: Tencent Cloud API Bucket
    • ACL: (optional) ACL applied to the uploaded files.
    • Expires: (optional) Expiration time of the signed URL. Default value is 360 seconds (6 minutes).
    • initOptions: (optional) Options passed to the constructor of the provider. You can find the complete list of options here.
    • uploadOptions: (optional) Options passed to the upload method. You can find the complete list of options here.
    • CDNDomain: (optional) CDN Accelerated Domain.
    • StorageRootPath: (optional) The storage path of the file in the bucket.

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.

Provider Configuration

./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_SecretId"),
        SecretKey: env("COS_SecretKey"),
        Region: env("COS_Region"),
        Bucket: env("COS_Bucket"),
      },
    },
  },
  // ...
});

Configuration for a private COS bucket and signed URLs

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_SecretId"),
        SecretKey: env("COS_SecretKey"),
        Region: env("COS_Region"),
        Bucket: env("COS_Bucket"),
        ACL: "private", // <= set ACL to private
      },
    },
  },
  // ...
});

Security Middleware Configuration

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,
        },
      },
    },
  },
  // ...
];

Configure the access domain (CDN acceleration)

./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_SecretId"),
        SecretKey: env("COS_SecretKey"),
        Region: env("COS_Region"),
        Bucket: env("COS_Bucket"),
      },
    },
  },
  // ...
});

Contribution

Feel free to fork and make a Pull Request to this plugin project. All the input is warmly welcome!

Install now

npm install strapi-provider-upload-tencent-cloud-storage

STATS

10 GitHub stars6 weekly downloads

Last updated

230 days ago

Strapi Version

Unavailable

Author

github profile image for Brian Yao
Brian Yao

Related plugin

Upload

Useful links

Create your own plugin

Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.