AWS S3 Provider - Not Working

System Information
  • Strapi Version: 4.1.2
  • Operating System: MacOS
  • Database: Postgres
  • Node Version: v16.13.1
  • NPM Version: 8.3.0
  • Yarn Version: 1.22.17

I just installed strapi-provider-upload-aws-s3 and followed all of the configuration steps provided in the documentation but media is still being added to the public/uploads folder instead of AWS and I canā€™t work out why. Iā€™ve configured plugins.js, middlewares.js and updated my bucket policy as follows:

{
    "Id": "Policy1",
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Action": [
              "s3:PutObject",
              "s3:GetObject",
              "s3:ListBucket",
              "s3:DeleteObject",
              "s3:PutObjectAcl"
            ],
            "Resource": [
              "arn:aws:s3::<Bucket Name>:",
              "arn:aws:s3:::<Bucket Name>/*"
            ],
            "Principal": "*"
        }
    ]
}

Does anyone know what might be causing this issue? I saw that there was a bug in version 3 but not sure if itā€™s related to that or something Iā€™m doing.

Iā€™m getting a bit confused because the NPM registry doesnā€™t use config{} but the Strapi docs do. Thereā€™s a youtube tutorial that uses the extensions folder but nothing seems to work.

OK ā€¦ just managed to do itā€¦

  1. Started a new Strapi project
  2. Used the plugins.js method with config
  3. Had to use provider long name rather than short one ā€˜strapi-provider-upload-aws-s3ā€™
module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: 'strapi-provider-upload-aws-s3',
      providerOptions: {
          accessKeyId: 'id',
          secretAccessKey: 'key',
          region:  'eu-west-2',
          params: {
              Bucket: 'Bucket'
          }
      },
    },
  },
  // ...
});```

Iā€™m still having issues. I have the short provider string in my default plugins.js file in /config. No issues on local / development. On production (Heroku), the long provider string in /config/env/production causes my server to fail start. When using the short url on production the server starts but when I test an upload I get a 500 error and also stating it was expecting a ā€œBucketā€ param but itā€™s there.

I also have this issue. I also am using Heroku to host it but unlike dmurphy779 I cannot get the files to upload at all to AWS. They still continue to go to the public folder even after the mentioned long/short string.

I also tried starting a new strapi project and then tried a different upload provider (cloudinary). Still uploads to the public folder instead of cloudinary.

Update. My issue was that since my production was on Heroku, I needed to define the config variables via the Heroku CLI as mention in the Heroku docs here: https://devcenter.heroku.com/articles/config-vars

Heroku does not read the .env file

@hwr7dd - show your plugins.js file and middleware.js file please.

@dmurphy779
plugin is word for word:

plugin.js:

module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: 'aws-s3',
      providerOptions: {
        accessKeyId: env('AWS_ACCESS_KEY_ID'),
        secretAccessKey: env('AWS_ACCESS_SECRET'),
        region: env('AWS_REGION'),
        params: {
          Bucket: env('AWS_BUCKET'),
        },
      },
    },
  },
  // ...
});

middleware is as well (replaced bucketname and region already):

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,
        },
      },
    },
  },
  // ...
];

I canā€™t get it to work on local either. I even tried switch to cloudinary. I did fresh install of strapi and the plugins and couldnā€™t get it to work.

As far as herokuā€™s env stuff yeah I also defined them there as I was familiar with how that works from prior projects.

Iā€™d be curious if youā€™re able to get this to work on a fresh install of strapi.

Figured it out. plugins.js vs plugin.js :man_facepalming:

5 Likes

Ok, this is really fun, I read a lot of posts about the S3 provider not working and finally, after spending 4 hours it was the solution, plugin.js vs plugins.js, I only checked that fileName because of your comment, if donā€™t, I think I would spent 4 more hours

1 Like

Can confirm I just had this same issue. I wonder if it was mentioned as Plugin.js somewhere, and not pluginsā€¦?