最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Strapi- Having issues with making AWS S3 my file upload provider - Stack Overflow

programmeradmin1浏览0评论

I'm following the directions on the Strapi site here: .x/plugins/upload.html#using-a-provider

Here is my plugin.js file located at ./config/plugins.js

module.exports = ({ env }) => ({
    upload: {
      provider: 'aws-s3',
      providerOptions: {
        accessKeyId: 'id',
        secretAccessKey: 'secret',
        region: 'us-east-1',
        params: {
          Bucket: 'bucket',
        },
      },
    }
  });

I have strapi-provider-upload-aws-s3 installed:

 "dependencies": {
    "knex": "<0.20.0",
    "pg": "^8.3.2",
    "sqlite3": "^5.0.0",
    "strapi": "3.1.4",
    "strapi-admin": "3.1.4",
    "strapi-connector-bookshelf": "3.1.4",
    "strapi-plugin-content-manager": "3.1.4",
    "strapi-plugin-content-type-builder": "3.1.4",
    "strapi-plugin-email": "3.1.4",
    "strapi-plugin-upload": "3.1.4",
    "strapi-plugin-users-permissions": "3.1.4",
    "strapi-provider-upload-aws-s3": "^3.1.4",
    "strapi-utils": "3.1.4"
  },

But when I go to my admin page on my local then go to plugins, I do not see a cog in the Media Library plugin which would allow me to change the settings.

I'm pretty stuck here, so help would be appreciated. Thank you!

I'm following the directions on the Strapi site here: https://strapi.io/documentation/v3.x/plugins/upload.html#using-a-provider

Here is my plugin.js file located at ./config/plugins.js

module.exports = ({ env }) => ({
    upload: {
      provider: 'aws-s3',
      providerOptions: {
        accessKeyId: 'id',
        secretAccessKey: 'secret',
        region: 'us-east-1',
        params: {
          Bucket: 'bucket',
        },
      },
    }
  });

I have strapi-provider-upload-aws-s3 installed:

 "dependencies": {
    "knex": "<0.20.0",
    "pg": "^8.3.2",
    "sqlite3": "^5.0.0",
    "strapi": "3.1.4",
    "strapi-admin": "3.1.4",
    "strapi-connector-bookshelf": "3.1.4",
    "strapi-plugin-content-manager": "3.1.4",
    "strapi-plugin-content-type-builder": "3.1.4",
    "strapi-plugin-email": "3.1.4",
    "strapi-plugin-upload": "3.1.4",
    "strapi-plugin-users-permissions": "3.1.4",
    "strapi-provider-upload-aws-s3": "^3.1.4",
    "strapi-utils": "3.1.4"
  },

But when I go to my admin page on my local then go to plugins, I do not see a cog in the Media Library plugin which would allow me to change the settings.

I'm pretty stuck here, so help would be appreciated. Thank you!

Share Improve this question asked Aug 24, 2020 at 12:20 ajohnson10209ajohnson10209 6641 gold badge6 silver badges16 bronze badges 2
  • 1 Is this related: github.com/strapi/strapi/issues/6625 – grohjy Commented Aug 24, 2020 at 15:00
  • @grohjy yes this did work! I still don't see the cog next to media library, but when I upload a picture, it goes to my cloudinary account! I really hope they update their documentation soon, I saw a lot of people who were having the same issues. Link: medium.com/@kwinten.yc.li/… – ajohnson10209 Commented Aug 24, 2020 at 23:26
Add a comment  | 

6 Answers 6

Reset to default 7

For Strapi V3

The Strapi upload plugin documentation has an error. https://docs.strapi.io/developer-docs/latest/plugins/upload.html#enabling-the-provider

Going by their docs' config code, I did not have functioning S3 upload; it would always upload locally.

Now my working S3 provider config looks like below. Essentially you just remove the config: { } sub-wrapper that their docs specify; it looks like it's not needed.

Doing this, I was able to upload media files through Strapi Dashboard (Plugins/Media Library), and the files would appear in my S3. Another indicator its working is it takes longer than local upload. Upload api list route works and shows my file URLs as full S3 urls.

config/plugins.js

upload: {
    provider: 'aws-s3',
    providerOptions: {
        accessKeyId: env('AWS_ACCESS_KEY_ID'),
        secretAccessKey: env('AWS_ACCESS_SECRET'),
        region:  env('AWS_REGION'),
        params: {
            Bucket: env('AWS_BUCKET')
        }
    }
}

For AWS, update ~/extensions/upload/config/settings.json file with below code to make it work:

{  
    "provider": "aws-s3",  
    "providerOptions": {
      "accessKeyId": "keyId",
      "secretAccessKey": "key",
      "region": "region",
      "params": {
        "Bucket": "bucket"
      }
   }
}

made these changes worked for me, and its the best way to use env variables instead of hard coded values: edit file config/plugin.js:

module.exports = ({ env }) => ({
upload: {
  provider: 'aws-s3'
  },
});

create a file extensions/upload/config/settings.js:

module.exports = {
provider: 'aws-s3',
providerOptions: {
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_ACCESS_SECRET,
  region: process.env.AWS_REGION,
  params: {
    Bucket: process.env.AWS_BUCKET_NAME,
  },
},
};

Pasting the following in the path ~/extensions/upload/config/settings.json worked for me:

{  
    "provider": "cloudinary",  
    "providerOptions": {
      "cloud_name": "Cloud Name",
      "api_key": "API Key",
      "api_secret": "Secret Key"  
   }
}

I still do not see the cog next to Media Library, but when I upload a picture, I see it in my cloudinary account. I really hope they update their documentation soon. This gave me a lot of trouble and I've seen a few others with this issue as well.

You are not supposed to change any settings regarding 3rd party providers for the Media Library on the Strapi Admin. Use the plugins.js file for configuring the provider.

Make your configurations there (copy your accessKeyId, secretAccessKey etc. from AWS) and then any uploads made from that point should be uploaded to your specified S3 bucket on AWS.

Side note: it is not a good idea to store private keys like secretAccessKey directly in your code, make sure to use environment variables for this purpose.

Just be sure of having the following structure on your .config/plugins.js In your example, you don't have the config object inside upload.

./config/plugins.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'),
        },
      }
    },
  },
  // ...
});

I hope this helps somebody, I was having the same issue and it was just that the config was missing inside the upload.

Saludos!

发布评论

评论列表(0)

  1. 暂无评论