# @mnightingale/strapi-provider-upload-aws-s3

> AWS S3 provider for strapi upload with additional configuration options

Latest version **4.0.0** (published 2021-12-06) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install @mnightingale/strapi-provider-upload-aws-s3
pnpm add @mnightingale/strapi-provider-upload-aws-s3
yarn add @mnightingale/strapi-provider-upload-aws-s3
bun add @mnightingale/strapi-provider-upload-aws-s3
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2021-12-06 |
| First published | 2021-12-06 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.x.x <=16.x.x |
| Dependencies | 1 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Michael Nightingale |
| Maintainers | mnightingale |
| Keywords | upload, aws, s3, strapi |

## Links

- npm: https://www.npmjs.com/package/@mnightingale/strapi-provider-upload-aws-s3
- Repository: https://github.com/mnightingale/strapi-provider-upload-aws-s3
- Homepage: https://github.com/mnightingale/strapi-provider-upload-aws-s3#readme
- Issues: https://github.com/mnightingale/strapi-provider-upload-aws-s3/issues
- npm.io page: https://npm.io/package/@mnightingale/strapi-provider-upload-aws-s3

## Dependencies (1)

- [aws-sdk](https://npm.io/package/aws-sdk.md) 2.892.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2021-12-06

## README

# @mnightingale/strapi-provider-upload-aws-s3

Adds a few enhancements to the default [@strapi/provider-upload-aws-s3](https://github.com/strapi/strapi/tree/master/packages/providers/upload-aws-s3) provider namely:

- Add a prefix to object paths
- Set a custom URL to resolve objects to (e.g. a CDN such as CloudFront)

## Resources

- [LICENSE](LICENSE)

## Links

- [Strapi website](https://strapi.io/)
- [Strapi documentation](https://docs.strapi.io)
- [Strapi community on Discord](https://discord.strapi.io)
- [Strapi news on Twitter](https://twitter.com/strapijs)

## Installation

```bash
# using yarn
yarn add @mnightingale/strapi-provider-upload-aws-s3

# using npm
npm install @mnightingale/strapi-provider-upload-aws-s3 --save
```

## Configurations

Your configuration is passed down to the provider. (e.g: `new AWS.S3(config)`). You can see the complete list of options [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property)

See the [using a provider](https://docs.strapi.io/developer-docs/latest/plugins/upload.html#using-a-provider) documentation for information on installing and using a provider. And see the [environment variables](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.html#environment-variables) for setting and using environment variables in your configs.

### Provider Configuration

`./config/plugins.js`

```js
module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: '@mnightingale/strapi-provider-upload-aws-s3',
      providerOptions: {
        accessKeyId: env('AWS_ACCESS_KEY_ID'),
        secretAccessKey: env('AWS_ACCESS_SECRET'),
        region: env('AWS_REGION'),
        params: {
          Bucket: env('AWS_BUCKET'),
        },
        prefix: env('AWS_PREFIX'),
        url: env('AWS_URL'),
      },
    },
  },
  // ...
});
```

### 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](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/required/middlewares.html#loading-order) documentation.

`./config/middlewares.js`

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

If you are using a custom URL you may want something more like

```js
module.exports = ({ env }) => {
  const cdn = env('AWS_URL') ? [new URL(env('AWS_URL')).hostname] : [];

  return [
    // ...
    {
      name: 'strapi::security',
      config: {
        contentSecurityPolicy: {
          directives: {
            'connect-src': ["'self'", 'https:'],
            'img-src': ["'self'", 'data:', 'blob:', ...cdn],
            'media-src': ["'self'", 'data:', 'blob:', ...cdn],
            upgradeInsecureRequests: null,
          },
        },
      },
    },
    // ...
  ];
};
```

## Required AWS Policy Actions

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

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

---
_Source: https://npm.io/package/@mnightingale/strapi-provider-upload-aws-s3 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
