Wondering what’s next for npm?Check out our public roadmap! »

strapi-provider-upload-aws-s3-resizing-and-optimisationTypeScript icon, indicating that this package has built-in type declarations

3.2.6 • Public • Published

strapi-provider-upload-aws-s3-resizing-and-optimisation

Installation

$ npm i strapi-provider-upload-aws-s3-resizing-and-optimisation

or

$ yarn add strapi-provider-upload-aws-s3-resizing-and-optimisation

Opportunities

  • Resizing and optimisation images by using sharp.js
  • Generation of images in webp format
  • Convenient file structure in AWS S3 Bucket

Configurations

Your configuration is passed down to the provider. (e.g: new AWS.S3(config))

Example

./config/plugins.js

module.exports = ({ env }) => ({
  upload: {
    provider: 'aws-s3-resizing-and-optimisation',
    providerOptions: {
      accessKeyId: env('AWS_ACCESS_KEY_ID'),
      secretAccessKey: env('AWS_ACCESS_SECRET'),
      region: env('AWS_REGION'),
      optimizeOptions: {
        jpeg: {
          quality: 90,
          progressive: true,
        },
        png: {
          quality: 90,
          progressive: true,
        },
        webp: {
          alphaQuality: 90,
        },
        tiff: {}
      },
      imageSizes: [
        {
          name: 'large',
          resizeOptions: {
            width: 1400
          },
          isGenerateWebp: true,
        },
        {
          name: 'medium',
          resizeOptions: {
            width: 700
          },
          isGenerateWebp: true,
        },
        {
          name: 'small',
          resizeOptions: {
            width: 550
          },
          isGenerateWebp: true,
        },
      ],
      params: {
        Bucket: env('AWS_BUCKET_NAME'),
      },
    },
  }
});

You can see another Sharp Optimize Options here and AWS S3 Params here

If you want to use a cdn instead of direct S3 access, you can just add a cdn url (i.e. https://whatever.cloudfront.net) to the config:

module.exports = ({ env }) => ({
  upload: {
    provider: 'aws-s3-resizing-and-optimisation',
    providerOptions: {
      accessKeyId: env('AWS_ACCESS_KEY_ID'),
      secretAccessKey: env('AWS_ACCESS_SECRET'),
      region: env('AWS_REGION'),
      cdn: env('CLOUDFRONT')
      ...

AWS S3 Bucket structure

+ images
  + origin
    - image1.jpeg
    - image2.png
    - image3.webp
    - image4.tiff
  + thumbnail
    - thumbnail_image1.jpeg
    - thumbnail_image2.png
    - thumbnail_image3.webp
    - thumbnail_image4.tiff
  + your-custom-size-format
    - image1.jpeg
    - image1.webp
    - image2.png
    - image2.webp
    - image3.webp
    - image4.tiff
    - image4.webp
  + your-another-custom-size-format
    - image1.jpeg
    - image1.webp
    - image2.png
    - image2.webp
    - image3.webp
    - image4.tiff
    - image4.webp
+ icons
  - icon.svg
+ files
  - presentation.pdf
  - document.txt

Install

npm i strapi-provider-upload-aws-s3-resizing-and-optimisation

DownloadsWeekly Downloads

448

Version

3.2.6

License

ISC

Unpacked Size

12.6 kB

Total Files

6

Last publish

Collaborators

  • avatar