strapi / strapi

🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable, and developer-first.
https://strapi.io
Other
63.29k stars 8k forks source link

Wrong bucket url after uploading video files from Strapi by using `@strapi/provider-upload-aws-s3` #21807

Open rb090 opened 20 hours ago

rb090 commented 20 hours ago

Bug report

The urls for uploaded video files are wrong saved into the DB.

I use Strapi v4.25.13 with the plugin @strapi/provider-upload-aws-s3 in version 4.25.13 to upload any kind of assets to a bucket.

I am not using AWS buckets. I am using OTC OBS buckets. But they work 100% the same like AWS buckets. We develop several services which were connected to OTC buckets and we were able to use the AWS SDK.

Required System information

Running yarn strapi report gave me the following output:

roxana@MacBook strapi-cms % yarn strapi report
yarn run v1.22.22
warning ../package.json: No license field
$ strapi report
Launched In: 288 ms
Environment: development
OS: darwin-arm64
Strapi Version: 4.25.13
Node/Yarn Version: yarn/1.22.22 npm/? node/v20.4.0 darwin arm64
Edition: Community
Database: mysql
✨  Done in 1.06s.

Describe the bug

The uploads are successful for different kind of files (images, pdfs) but for videos, the upload url is wrong.

For any kind of videos, the url in the DB looks sth like this: https:///<BUCKET-NAME>/myvideo.mp4.

Instead of the custom endpoint I set up in my plugins.js.

Is there a chance that my plugins.js is somehow wrong and I only need to correct sth?

Steps to reproduce the behavior

  1. Have a Strapi with setup @strapi/provider-upload-aws-s3 plugin and connected bucket
  2. Go to your Strapi instance
  3. Go to media library
  4. Upload any kind of video
  5. Check files table in the database and check the url property. It has corrupted url.

Expected behavior

I expect that the file.url corresponds defined endpoint in plugin.js and the filename is appended at the end -> https://obs.${env("AWS_REGION")}.otc.t-systems.com/filename.extension. Like it behaves when uploading images or any other type of files.

Screenshots

NONE

Code snippets

My plugins.js:

module.exports = ({ env }) => ({
  upload: {
    config: {
      provider: "aws-s3",
      providerOptions: {
        s3Options: {
          credentials: {
            accessKeyId: env("AWS_ACCESS_KEY_ID"),
            secretAccessKey: env("AWS_ACCESS_SECRET"),
          },
          region: env("AWS_REGION"),
          endpoint: `https://obs.${env("AWS_REGION")}.otc.t-systems.com`,
          params: {
            ACL: "private",
            signedUrlExpires: env("AWS_SIGNED_URL_EXPIRES") || 15 * 60,
            Bucket: env("AWS_BUCKET"),
          },
        },
      },
      actionOptions: {
        upload: {},
        uploadStream: {},
        delete: {},
      },
    },
  },
});

My middlewares.js:

module.exports = [
  "strapi::errors",
  {
    name: "strapi::security",
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "connect-src": ["'self'", "https:"],
          "img-src": [
            "'self'",
            "data:",
            "blob:",
            `${process.env.AWS_BUCKET}.obs.${process.env.AWS_REGION}.otc.t-systems.com`,
          ],
          "media-src": [
            "'self'",
            "data:",
            "blob:",
            `${process.env.AWS_BUCKET}.obs.${process.env.AWS_REGION}.otc.t-systems.com`,
          ],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  "strapi::poweredBy",
  "strapi::cors",
  "strapi::logger",
  "strapi::query",
  "strapi::body",
  "strapi::session",
  "strapi::favicon",
  "strapi::public",
];

Additional context

I installed the plugin to my Strapi project with yarn add @strapi/provider-upload-aws-s3@4.25.13

bolg55 commented 16 hours ago

Can you just confirm you are using plugins.js and not plugin.js as your issue suggests?

rb090 commented 16 hours ago

Oh no I am sorry for this. That was a typo (auto correction on Mac I overseen 😞). Yes I confirm that the name of the file is plugins.js. I also corrected the issue description regarding this.