Hi All, I have strapi v4.20 and I am unable to upload files to the media library. I tried with 2 plugins first time with aws-s3 and second time with “local server”. It gives me the same error message like in the screenshot below with both the options.
![image](https://d38xoolefqxt5u.cloudfront.net/original/3X/1/d/1db2ac4f4da6a6738164fdcda1a32e449a2aa23c.png)
when I inspect the response from the browser, I get a message error 403 with both the plugins above. Can someone help to point me the right direction to resolve this issue?
plugins.ts with local upload
export default ({ env }) => ({
upload: {
config: {
providerOptions: {
localServer: {
maxage: 300000
},
},
},
},
});
middleware.ts when with local and s3 upload option
export default [
‘strapi::logger’,
‘strapi::errors’,
‘strapi::cors’,
‘strapi::poweredBy’,
‘strapi::query’,
‘strapi::session’,
‘strapi::favicon’,
‘strapi::public’,
{
name: ‘strapi::security’,
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
‘connect-src’: [“‘self’”, ‘https:’],
‘img-src’: [
“‘self’”,
‘data:’,
‘blob:’,
‘market-assets.strapi.io’,
‘https://bucketname.s3.ap-southeast-1.amazonaws.com/’, //tried with various URL (with region, without region none works, same error)
],
‘media-src’: [
“‘self’”,
‘data:’,
‘blob:’,
‘market-assets.strapi.io’,
‘https://bucketname.s3.ap-southeast-1.amazonaws.com/’, //tried with various URL (with region, without region none works, same error)
],
upgradeInsecureRequests: null,
},
},
},
},
// …
// …
{
name: “strapi::body”,
config: {
formLimit: “256mb”, // modify form body
jsonLimit: “256mb”, // modify JSON body
textLimit: “256mb”, // modify text body
formidable: {
maxFileSize: 250 * 1024 * 1024, // multipart data, modify here limit of uploaded file size
},
},
},
// …
];
pluginst.ts with s3 upload
module.exports = ({ env }) => ({
// …
upload: {
config: {
provider: ‘aws-s3’,
providerOptions: {
s3Options: {
accessKeyId: env(‘AWS_ACCESS_KEY_ID’),
secretAccessKey: env(‘AWS_ACCESS_SECRET’),
region: env(‘AWS_REGION’),
params: {
ACL: env(‘AWS_ACL’, ‘private’),
Bucket: env(‘AWS_BUCKET’),
},
},
},
actionOptions: {
upload: {},
uploadStream: {},
delete: {},
},
},
},
// …
});
.env
HOST=0.0.0.0
PORT=1337
APP_KEYS=xxxxx
API_TOKEN_SALT=xxxxx
ADMIN_JWT_SECRET=xxxxxx
TRANSFER_TOKEN_SALT=xxxxx
Database
DATABASE_CLIENT=mysql
DATABASE_HOST=xxxx
DATABASE_PORT=3306
DATABASE_NAME=strapi
DATABASE_USERNAME=xxx
DATABASE_PASSWORD=xxx
DATABASE_SSL=true
JWT_SECRET=xxxx
#AWS-S3-Bucket-to-upload-assets
AWS_BUCKET_NAME=strapi-poc-bucket
AWS_REGION=ap-southeast-1
AWS_ACCESS_KEY_ID=xxxx
AWS_ACCESS_SECRET=xxxx
CORS_ALLOWED_ORIGINS=[“*”]