Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@airteam/strapi-provider-upload-aws-s3-advanced

Package Overview
Dependencies
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@airteam/strapi-provider-upload-aws-s3-advanced

AWS S3 provider for strapi upload with more advanced configuration options

  • 4.0.8
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
4
Weekly downloads
 
Created
Source

strapi-provider-upload-aws-s3-advanced

Configurations

This extends the original configurability of the provider by adding both a baseUrl, which may be your CDN URL, which replaces the endpoint returned from AWS with a custom URL, and prefix, which does exactly that: prefixes the object's path such that we do not strictly upload into the buckets root directory. This can be used to keep the bucket organized.

Everything else follows the regular strapi-provider-upload-aws-s3 schema.

Your configuration is passed down to the provider. (e.g: new AWS.S3(config)). You can see the complete list of options here

See the using a provider documentation for information on installing and using a provider. And see the environment variables for setting and using environment variables in your configs.

Example

./config/plugins.js

module.exports = ({ env }) => ({
  // ...
  upload: {
    provider: "aws-s3-advanced",
    providerOptions: {
      accessKeyId: env("AWS_ACCESS_KEY_ID"),
      secretAccessKey: env("AWS_ACCESS_SECRET"),
      region: env("AWS_REGION"),
      params: {
        bucket: env("AWS_BUCKET"),
      },
      baseUrl: env("CDN_BASE_URL"), // e.g. https://cdn.example.com, this is stored in strapi's database to point to the file
      prefix: env("BUCKET_PREFIX"), // e.g. strapi-assets, note the missing slash at the start
    },
  },
  // ...
});

If using strapi >= 4.0.0, please use the below config:

./config/plugins.js

module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: "strapi-provider-upload-aws-s3-advanced",
      providerOptions: {
        accessKeyId: env("AWS_ACCESS_KEY_ID"),
        secretAccessKey: env("AWS_ACCESS_SECRET"),
        region: env("AWS_REGION"),
        params: {
          bucket: env("AWS_BUCKET"),
        },
        baseUrl: env("CDN_BASE_URL"), // e.g. https://cdn.example.com, this is stored in strapi's database to point to the file
        prefix: env("BUCKET_PREFIX"), // e.g. strapi-assets, note the missing slash at the start
      },
    },
  },
  // ...
});

Note: If you are migrating from a pre-4.0.0 version (i.e. v3.6.8 or earlier), the files relation will include aws-s3-advanced as the provider. Previously, the prefix "strapi-upload-provider" was assumed to always be present for upload provider plugins. This is no longer the case in >= 4.0.0, hence when uploading with the newer version of this provider, strapi will insert new files with the full provider package name, i.e., strapi-provider-upload-aws-s3-advanced. See Migration for details on the required manual work.

Image Previews

To allow the thumbnails to properly populate, add the below config to

./config/middlewares.js

module.exports = ({ env }) => [
  // ...
  {
    name: "strapi::security",
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "connect-src": ["'self'", "https:"],
          "img-src": ["'self'", "data:", "blob:", `${env("CDN_BASE_URL")}`],
          "media-src": ["'self'", "data:", "blob:", `${env("CDN_BASE_URL")}`],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  // ...
];

Migration

v3.x to v4.0.x

Strapi now uses the full package name as provider name, as seen in the configuration of the provider in the Example section above. This means that the relation will include different provider names when using the newer version of this provider with strapi >= 4.0.0 on data from pre-4.0.0. In particular, you will find that the pre-4.0.0 files will have the provider aws-s3-advanved, while the newer ones will have strapi-provider-aws-s3-advanved. If you're not going to change the existing files in your CDN, you will not need to take any actions. The provider attribute is only used for mapping the handler for creating or deleting files to the handlers defined in this provider. Files will remain readable with the old provider and new files will be added with the new provider name. Only if you want to delete old files from the new provider, you will be required to adapt the files table.

In strapi >= 4.0.0, only SQL databases are officially supported, so we will only provide queries for the supported backends:

PostgreSQL
UPDATE files SET provider = 'strapi-provider-upload-aws-s3-advanced' WHERE provider = 'aws-s3-advanced';
MySQL
UPDATE `files` SET `provider` = `strapi-provider-upload-aws-s3-advanced` WHERE `provider` = `aws-s3-advanced`;
SQLite
UPDATE files SET provider = 'strapi-provider-upload-aws-s3-advanced' WHERE provider = 'aws-s3-advanced';

Resources

  • License

Keywords

FAQs

Package last updated on 13 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc