Strapi v4로 콘텐츠 보안 정책 지시문을 수정하고 AWS S3에 업로드하는 방법
6564 단어 webdevjavascriptstrapi
문제는 두 버전 간에 (분명히) 변경된 몇 가지 사항과 @strapi/provider-upload-aws-s3 플러그인에 대한 이전 구성이 더 이상 작동하지 않는다는 것입니다.
글쎄요.
파일을 업로드하려고 하면 다음과 같이 표시됩니다.

하나의 이미지는 로컬로 업로드되고 다른 하나는 S3에 업로드되었으며, 내가 찾은 것은 구성이 작동하고 실제로 이미지가 AWS S3의 버킷에 업로드되고 있지만 CMS에서 표시를 거부한다는 것입니다.
그래서 Google에서 시간을 보낸 후 마침내 this GitHub issue 및 이 other issue에서 찾을 수 있는 해결책을 찾았습니다.
제 경우에는 지역을 s3 URL에 추가하기 위해 약간 조정해야 했습니다.
하지만 기본적으로 해야 할 일은
config/middlewares.js
파일을 다음 구성으로 업데이트하는 것입니다.// From this:
module.exports = [
'strapi::errors',
'strapi::security',
... //rest of middlewares
];
// To this
module.exports = ({ env }) => [
'strapi::errors',
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': [
"'self'",
'data:',
'blob:',
'res.cloudinary.com', // cloudinary images
'lh3.googleusercontent.com', // google avatars
'platform-lookaside.fbsbx.com', // facebook avatars
'dl.airtable.com', // strapi marketplace
`https://${env('AWS_BUCKET')}.s3.${env('AWS_REGION')}.amazonaws.com`
],
'media-src': ["'self'", 'data:', 'blob:', `https://${env('AWS_BUCKET')}.s3.${env('AWS_REGION')}.amazonaws.com`],
upgradeInsecureRequests: null,
},
},
},
},
... //rest of middlewares
];
그리고 이제 Strapi는 마침내 S3에서 업데이트된 파일로 작업해야 합니다.
Note
If you wonder why I had to addres.cloudinary.com
and other domains, it's simply to allow icons and images to work in Strapi, like in the marketplace.
Reference
이 문제에 관하여(Strapi v4로 콘텐츠 보안 정책 지시문을 수정하고 AWS S3에 업로드하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/darkmavis1980/how-to-fix-the-content-security-policy-directive-with-strapi-v4-and-upload-on-aws-s3-3bp2텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)