Skip to content

Instantly share code, notes, and snippets.

@Kassan424kh
Last active May 1, 2025 08:38
Show Gist options
  • Select an option

  • Save Kassan424kh/39d50ad65a1aa6799b9ece38ef91fcdc to your computer and use it in GitHub Desktop.

Select an option

Save Kassan424kh/39d50ad65a1aa6799b9ece38ef91fcdc to your computer and use it in GitHub Desktop.
Strapi + Minio

بسم الله الرحمن الرحيم

Strapi + Minio

  1. install npm package: npm i strapi-provider-upload-ts-minio
  2. add upload module in plugins.js
    module.exports = ({env}) => ({
      upload: {
              config: {
                  provider: "strapi-provider-upload-ts-minio",
                  providerOptions: {
                      accessKey: env('MINIO_ACCESS_KEY'),
                      secretKey: env('MINIO_SECRET_KEY'),
                      bucket: env('MINIO_BUCKET'),
                      endPoint: env('MINIO_ENDPOINT'),
                      port: 443,
                      useSSL: true
                  },
                  actionOptions: {
                      upload: {
                          sizeLimit: 200 * 1024 * 1024, // 200MB
                      },
                  },
              },
          },
      ...  
    });
  3. add variables to .env
    MINIO_ACCESS_KEY=#################
    MINIO_SECRET_KEY=#################
    MINIO_BUCKET=#################
    MINIO_ENDPOINT=https://#################
    MINIO_USE_SSL=true
  4. replace strapi::security in middlewares.js
    ...
    {
      name: 'strapi::security',
      config: {
          contentSecurityPolicy: {
              useDefaults: true,
              directives: {
                  'connect-src': ["'self'", 'https:'],
                  'img-src': [
                      "'self'",
                      'data:',
                      'blob:',
                      'market-assets.strapi.io',
                      '<<<endPoint>>>',
                  ],
                  'media-src': [
                      "'self'",
                      'data:',
                      'blob:',
                      'market-assets.strapi.io',
                      '<<<endPoint>>>',
                  ],
                  upgradeInsecureRequests: null,
              },
          },
      },
    },
    ...
  5. Login to minio ui page
  6. create new bucket
  7. set Access Policy to:
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Principal": {
                    "AWS": [
                        "arn:aws:iam::minio:user/<<<accessKey>>>"
                    ]
                },
                "Action": [
                    "s3:GetBucketLocation",
                    "s3:ListBucket",
                    "s3:ListBucketMultipartUploads"
                ],
                "Resource": [
                    "arn:aws:s3:::<<<bucket-name>>>"
                ]
            },
            {
                "Effect": "Allow",
                "Principal": {
                    "AWS": [
                        "arn:aws:iam::minio:user/<<<accessKey>>>"
                    ]
                },
                "Action": [
                    "s3:AbortMultipartUpload",
                    "s3:DeleteObject",
                    "s3:GetObject",
                    "s3:ListMultipartUploadParts",
                    "s3:PutObject"
                ],
                "Resource": [
                    "arn:aws:s3:::<<<bucket-name>>>/*"
                ]
            },
            {
                "Effect": "Allow",
                "Principal": {
                    "AWS": [
                        "*"
                    ]
                },
                "Action": [
                    "s3:GetObject"
                ],
                "Resource": [
                    "arn:aws:s3:::<<<bucket-name>>>/*"
                ]
            }
        ]
    }

Done

الحمد لله

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment