Reputation: 664
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!
Upvotes: 7
Views: 8980
Reputation: 11286
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')
}
}
}
Upvotes: 7
Reputation: 1
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!
Upvotes: 0
Reputation: 123
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,
},
},
};
Upvotes: 3
Reputation: 41
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"
}
}
}
Upvotes: 4
Reputation: 121
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.
Upvotes: 0
Reputation: 664
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.
Upvotes: 1