Code Monkey home page Code Monkey logo

strapi-provider-upload-tencent-cloud-storage's Introduction

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:

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:

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:

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 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!

strapi-provider-upload-tencent-cloud-storage's People

Contributors

yclgkd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

strapi-provider-upload-tencent-cloud-storage's Issues

Request: add uploadStream support

Metadata

Strapi version: 4.14.2
Plugin version: 1.1.4
Node version: 18.18.2
Command ran to start the service: node --trace-warnings /opt/node_modules/@strapi/strapi/bin/strapi.js start

Plugin config:

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

Content of the environment variables:

COS_SECRETID="not-set"
COS_SECRETKEY="not-set"
COS_REGION="ap-shanghai"
COS_BUCKET="XXXXX"

Issue

The strapi-provider-upload-tencent-cloud-storage plugin isn't getting loaded at startup time of Strapi. It falls back to the default upload method.
We see this message when starting the service regarding the uploadStream feature:

(node:1) Warning: The upload provider "strapi-provider-upload-tencent-cloud-storage" doesn't implement the uploadStream function. Strapi will fallback on the upload method. Some performance issues may occur.
    at createProvider (/opt/node_modules/@strapi/plugin-upload/server/register.js:73:13)
    at module.exports [as register] (/opt/node_modules/@strapi/plugin-upload/server/register.js:16:38)
    at Object.register (/opt/node_modules/@strapi/strapi/dist/core/domain/module/index.js:49:52)
    at Object.register (/opt/node_modules/@strapi/strapi/dist/core/registries/modules.js:29:27)
    at async Strapi.runLifecyclesFunctions (/opt/node_modules/@strapi/strapi/dist/Strapi.js:509:9)
    at async Strapi.register (/opt/node_modules/@strapi/strapi/dist/Strapi.js:428:9)
    at async Strapi.load (/opt/node_modules/@strapi/strapi/dist/Strapi.js:493:9)
    at async Strapi.start (/opt/node_modules/@strapi/strapi/dist/Strapi.js:273:17)

I noticed that the feature was still enabled in [email protected] so I tried that version and got this issue when trying to upload a media. The credentials are not set at the moment (I've set placeholders), but I wanted to share the output as it's not obvious to me on what it's reporting:

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".] {
  code: 'ERR_UNHANDLED_REJECTION'
}
Screenshot 2023-10-19 at 21 14 27

Let me know if you need more info. Thanks!

报错了 tunneling socket could not be established, cause=connect ECONNREFUSED ::1:80

image

upload cos <<<<<<<
{
err: {
code: 'ECONNRESET',
name: 'ECONNRESET',
message: 'tunneling socket could not be established, cause=connect ECONNREFUSED ::1:80',
url: 'https://img-1258455507.cos.ap-shanghai.tencentcos.cn/logo_99_1eb22b251e.png',
method: 'PUT'
},
data: undefined,
size: 6.38
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which
was not handled with .catch(). The promise rejected with the reason "#".] {
code: 'ERR_UNHANDLED_REJECTION'
}

Apply CDN domain to images uploaded before configuring the feature.

Hi,

I'm working on setting up the CDN feature in the strapi-provider-upload-tencent-cloud-storage plugin in order to pull images from a publicly available URL.

Example of the URL I'm seeing by inspecting the strapi database:

mysql> select url from files;
+---------------------------------------------------------------------------------------------------+
| url                                                                                               |
+---------------------------------------------------------------------------------------------------+
| https://bucket-url*.myqcloud.com/default_avatar.png |
| https://bucket-url*.myqcloud.com/gif_aaf93c6e3a.gif            |
| https://cdn-url/media/2024_01_31_10_54_ea250fb1b2.png                               |
+---------------------------------------------------------------------------------------------------+

After running some tests locally, the issue we're facing is that the URL for the images that were uploaded before setting the CDN domain still points to the domain of the bucket finishing with *myqcloud.com.

Is there a way to ensure that all the images now points to the CDN domain no matter when they were uploaded?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.