500 server error while trying to upload images

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

Hi everyone,

I have strapi set up locally and was using no image upload provider. Once I set up my provider to AWS s3, I keep getting 500 error, and I can’t upload images anymore.

I get such errors:

Any ideas what did I do wrong and how to fix it?

My settings for AWS s3 upload:

Hey @forexlit, did you have a look at the Strapi log? You can most likely see the exception & message there. If you find it and can’t fix it yourself. Post it here, than we can try to help you.

I was having trouble getting the configuration settings correct for the AWS credentials and was getting the same error. I also saw “bucket name missing” in the logs. So in case this helps save someone else some time, here is what happened to me. I’m sure this is obvious to the more experienced programmers out there.

I was entering the credentials incorrectly into the configuration file. I was editing ./config/plugins.js:

Here is the sample file from the guide:

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

So I was replacing what I thought were placeholder strings above. like this-

module.exports = ({ env }) => ({
  upload: {
    provider: 'aws-s3',
    providerOptions: {
      accessKeyId: env('FAKEISFJISJDISJD'),
      secretAccessKey: env('FAKEOINAD%#$ONION(SBASMKNSKDNS^%#^%'),
      region: 'us-west-1',
      params: {
        Bucket: 'bucketname',
      },
    },
  },
});

That’s wrong - I realized you are setting environment variables and need the variable names! So you add the data after a comma like this:

module.exports = ({ env }) => ({
upload: {
provider: ‘aws-s3’,
providerOptions: {
accessKeyId: env(‘AWS_ACCESS_KEY_ID’, ‘FAKE6FHWIDHIWD4XPQ’),
secretAccessKey: env(‘AWS_ACCESS_SECRET’, ‘Fakeadsfi+IeidnansdVkbT6Ji8BIJiojafffa5gy5C0’),
region: env(‘AWS_REGION’, ‘us-west-1’),
params: {
Bucket: env(‘AWS_BUCKET_NAME’, ‘bucketname-strapi’),
},
},
},
});

SO the sample file really should look like this to be more clear:
module.exports = ({ env }) => ({
upload: {
provider: ‘aws-s3’,
providerOptions: {
accessKeyId: env(‘AWS_ACCESS_KEY_ID’, ‘Your_access_key’),
secretAccessKey: env(‘AWS_ACCESS_SECRET’, ‘Your_access_secret’),
region: env(‘AWS_REGION’, ‘us-west-1’),
params: {
Bucket: env(‘AWS_BUCKET_NAME’, ‘bucketname-strapi’),
},
},
},
});

Hope this save someone some time!

1 Like

I found the env vars were not working. I tested out hardcoding them and it worked.

I’m thinking an npm package like dotenv might work better than env() syntax.