1.0.0 • Published 8 months ago

strapi-provider-upload-cloud-object-storage v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

A provider for strapi server to upload file to Tencent COS.

Installation

npm install strapi-provider-upload-cloud-object-storage --save

Usage

strapi v4, See example below for ./config/plugins.js

export default ({ env }) => ({
    upload: {
      config: {
        provider: 'strapi-provider-upload-cloud-object-storage', // the full name
        providerOptions: {
          appId: env('COS_APPID'),
          secretId: env('COS_SECRET_ID'), 
          secretKey: env('COS_SECRET_KEY'),
          region: env('COS_REGION'),
          bucket: env('COS_BUCKET'),
          basePath: env('COS_BASE_PATH'),
        },
      },
    }
});

Provider Options

PropertyTypeValue
COS_APPIDstringtencent appid
COS_SECRET_IDstringtencent secreted id
COS_SECRET_KEYstringtencent secreted key
COS_REGIONstringcosregion
COS_BUCKETstringbucket name
COS_BASE_PATHstringpath to store the file, e.g. strapi-cms/

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

export default ({ env }) => { return [
  // ...
  { 
    name: "strapi::security",
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "connect-src": ["'self'", "https:"],
          "img-src": [
            "'self'",
            "data:",
            "blob:",
            `${env('COS_BUCKET')}-${env('COS_APPID')}.cos.${env('COS_REGION')}.myqcloud.com` 
          ],
          "media-src": [
            "'self'", 
            "data:",
            "blob:", 
            `${env('COS_BUCKET')}-${env('COS_APPID')}.cos.${env('COS_REGION')}.myqcloud.com`
          ],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  // ...
];
}

Reference

1.0.0

8 months ago