
By Arju S Moon
Plugin to upload media files to a private s3 bucket, and serve the image using cloudfront CDN. This will allow the user to create private S3 buckets, and still be able to serve images from the bucket using CDN.
released October 3, 2023
npm install provider-upload-aws-s3-cfUsing AWS S3 in combination with Amazon CloudFront offers several benefits over using an S3 bucket as a public content repository. You can get it working in under 2 minutes in your application. EASY!
# using npm
npm install @strapi/provider-upload-aws-s3Add the folling lines of code in the file: config/plugins.js
module.exports = ({ env }) => ({
upload: {
config: {
provider: "provider-upload-aws-s3-cf",
providerOptions: {
s3Options: {
accessKeyId: env("AWS_ACCESS_KEY_ID"),
secretAccessKey: env("AWS_ACCESS_SECRET"),
region: env("AWS_REGION"),
params: {
signedUrlExpires: env("AWS_SIGNED_URL_EXPIRES", 15 * 60),
Bucket: env("AWS_BUCKET"),
},
cdn: env("AWS_CDN"),
},
},
},
},
});Add the folling lines of code in the file: config/middlewares.js. You can comment out or remove the existing strapi::security from the middleware array.
{
name: "strapi::security",
config: {
contentSecurityPolicy: {
directives: {
"script-src": ["'self'", "'unsafe-inline'", "cdn.jsdelivr.net"],
"img-src": [
"'self'",
"data:",
"blob:",
"cdn.jsdelivr.net",
"strapi.io",
`${env("AWS_BUCKET")}.s3.${env("AWS_REGION")}.amazonaws.com`,
`${env("AWS_CDN")}`,
],
},
},
},
}AWS_ACCESS_KEY_ID=<>
AWS_ACCESS_SECRET=<>
AWS_REGION=<>
AWS_BUCKET=<>
AWS_CDN=<>Any bugs/issues you may face can be submitted as issues in the Github repo.
Share your work with the community and get it listed in the Strapi ecosystem for everyone to discover and use.
Submit
