Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tencent COS provider for Strapi

License

NotificationsYou must be signed in to change notification settings

yclgkd/strapi-provider-upload-tencent-cloud-storage

Repository files navigation

Resources

Links

Installation

# using yarnyarn add strapi-provider-upload-tencent-cloud-storage# using npmnpm 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 ofoptions here.
    • uploadOptions: (optional) Options passed to theupload method. You can find the complete list ofoptions here.
    • CDNDomain: (optional) CDN Accelerated Domain.
    • StorageRootPath: (optional) The storage path of the file in the bucket.

See thedocumentation about using a provider for information on installing and using a provider. To understand how environment variables are used in Strapi, please refer to thedocumentation about environment variables.

Provider Configuration

./config/plugins.js or./config/plugins.ts for TypeScript projects:

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

Configuration for a private COS bucket and signed URLs

If your bucket is configured to be private, you will need to set theACL option toprivate in theparams 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 theExpires option in theproviderOptions object. The default value is 360 seconds (6 minutes).

./config/plugins.js or./config/plugins.ts for TypeScript projects:

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

Security Middleware Configuration

Due to the default settings in the Strapi Security Middleware you will need to modify thecontentSecurityPolicy settings to properly see thumbnail previews in the Media Library. You should replacestrapi::security string with the object bellow instead as explained in themiddleware configuration documentation.

./config/middlewares.js or./config/middlewares.ts for TypeScript projects:

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:

module.exports=({ env})=>({// ...upload:{config:{provider:"strapi-provider-upload-tencent-cloud-storage",providerOptions:{CDNDomain:"example-cdn-domain.com",// <= CDN Accelerated DomainSecretId:env("COS_SECRET_ID"),SecretKey:env("COS_SECRET_KEY"),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!


[8]ページ先頭

©2009-2025 Movatter.jp