-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
Bug report
Describe the bug
By configuring a custom upload provider in config/plugins.js as described in the documentation docs, Strapi is not using the configured provider but instead, it is still using the default one (@strapi/provider-upload-local)
Steps to reproduce the behaviour
Note: ENV Variables and the S3 bucket are correctly set
- Install @strapi/provider-upload-aws-s3
- Create the file
config/plugins.jsas explained here:
module.exports = ({ env }) => ({
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'),
},
}
}
})- run
npm run build && npm run startornpm run develop - Open the admin panel and navigate into the media libraries section
- Upload a file
By checking your bucket you will not see any new file, instead, you can see the new file inside the public folder.
I also place a console.log inside node_modules/@strapi/provider-upload-local upload function
and inside node_modules/@strapi/provider-upload-aws-s3 upload function and in fact only @strapi/provider-upload-local is executed.
Expected behaviour
It should use the new provider configuration.
System
- Node.js Version: v14.17.5
- NPM version: 6.14.14
- Strapi version: v4
- Operating system: Mac OS Catalina 10.15.7
Which alternatives I tried
- Using the old library
strapi-provider-upload-aws-s3instead of the@strapi/provider-upload-aws-s3(not working) - Create a json configuration inside
src/extensions/upload/config/settings.json(not working) - Create a js configuration inside
src/extensions/upload/config/settings.js(not working) - Using npm local paths to rename the new library
@strapi/provider-upload-aws-s3tostrapi-provider-upload-aws-s3as suggested in the documentation for the scoped packages docs (not working) - Create a local provider (not working) docs
Workaround
I managed to get the aws-s3 provider work in this way:
- Create a local provider in
./providers/my-upload-provider/ - I copied the
./node_modules/@strapi/provider-upload-aws-s3into my provider folder - Since the configuration file written inside
./configuration /plugins.jsseems not to be provided to our custom provider, we edit the./providers/my-upload-provider/lib/index.jsby adding the right config:
module.exports = {
init(config) {
// I add my configuration here
const configInternal = {
accessKeyId: process.env.AWS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_KEY,
region: process.env.AWS_REGION,
params: {
Bucket: process.env.AWS_BUCKET_NAME,
},
}
const S3 = new AWS.S3({
apiVersion: '2006-03-01',
...config,
// And than I passed the configuration to AWS.S3
...configInternal,
});
...
}- I force npm to override the
@strapi/provider-upload-localwith my custom provider by using npm local paths:
package.json
{
...
"dependencies": {
...
"@strapi/provider-upload-local": "file:providers/my-upload-provider",
}
}- Run
yarn install && yarn develop
It works for me
Note: I had other issues after this fix, related to CORS. It can be fixed by following this: #11637
UPDATE
It seems a docs mistake. Scroll down to the comments to read the solution.