Skip to content

Dreamink-Official/strapi-upload-aws-s3-imagemagick-assetmanager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 

Repository files navigation

strapi-upload-aws-s3-imagemagick

Links

Installation

This plugin uses imagemagick cli. It could happen that some cli commands need to be adapted based on your operation system install imagemagick (used: ImageMagick-7.1.0-46-Q16-HDRI-x64-dll)

Using npm

npm install https://github.com/DreamInk-Offical/strapi-upload-aws-s3-imagemagick-assetmanager.git --save

Configuration

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.

  • resizeOptions can be found here
  • optional commands - not integrated can be found here

Provider Configuration

./config/plugins.js

module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: 'strapi-upload-aws-s3-imageMagick-assetmanager',
      providerOptions: {
        accessKeyId: env('WASABI_ACCESS_KEY_ID'),
        secretAccessKey: env('WASABI_ACCESS_SECRET'),
        endpoint: env('WASABI_ENDPOINT'),
        params: {
          Bucket: env('WASABI_BUCKET'),
        },
        imageSizes: [
          {
            name: '2k',
            resizeOptions: {
              options: '-resize 2048x2048 -quality 100'
            }
          },
          {
            name: '4k',
            resizeOptions: {
              options: '-resize 4096x4096 -quality 100'
            }
          },
          {
            name: '8k',
            resizeOptions: {
              options: '-resize 8192x8192 -quality 100'
            }
          }          
        ],
      },
    },
  },
  // ...
});

API Parameters

/api/upload

Parameter Description
files The file(s) to upload. The value(s) can be a Buffer or Stream.
path (optional) The folder where the file(s) will be uploaded (json string - {"upload_path": "assets/id_123123"}.
path (imageSizes) Specify image sizes (json string - {"upload_path": "assets/id_123123", "imageSizes": "8k,4k,2k"}.
refId The ID of the entry which the file(s) will be linked to.
ref The unique ID (uid) of the model which the file(s) will be linked to (see more below).
source (optional) The name of the plugin where the model is located.
field The field of the entry which the file(s) will be precisely linked to.

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

module.exports = [
  // ...
  {
    name: 'strapi::security',
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          'connect-src': ["'self'", 'https:'],
          'img-src': [
            "'self'",
            'data:',
            'blob:',
            'dl.airtable.com',
            'yourBucketName.s3.yourRegion.amazonaws.com',
          ],
          'media-src': [
            "'self'",
            'data:',
            'blob:',
            'dl.airtable.com',
            'yourBucketName.s3.yourRegion.amazonaws.com',
          ],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  // ...
];

If you use dots in your bucket name, the url of the ressource is in directory style (s3.yourRegion.amazonaws.com/your.bucket.name/image.jpg) instead of yourBucketName.s3.yourRegion.amazonaws.com/image.jpg. Then only add s3.yourRegion.amazonaws.com to img-src and media-src directives.

Required AWS Policy Actions

These are the minimum amount of permissions needed for this provider to work.

"Action": [
  "s3:PutObject",
  "s3:GetObject",
  "s3:ListBucket",
  "s3:DeleteObject",
  "s3:PutObjectAcl"
],

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published