Skip to content

Commit 7013873

Browse files
committed
[migrate] replace AWS S3 provider with CloudFlare R2 for uploading (fix #1)
1 parent 9259e80 commit 7013873

File tree

5 files changed

+292
-1630
lines changed

5 files changed

+292
-1630
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Strapi comes with a full featured [Command Line Interface][1] (CLI) which lets y
2121
### Back-end
2222

2323
1. [Swagger document][11]
24-
2. [AWS S3 uploader][12] (with CloudFlare R2 compatibility)
24+
2. [CloudFlare R2 uploader][12]
2525

2626
### Front-end
2727

@@ -147,7 +147,7 @@ Feel free to check out the [Strapi GitHub repository][34]. Your feedback and con
147147
[9]: https://www.docker.com/
148148
[10]: https://github.com/features/actions
149149
[11]: https://github.com/strapi/strapi/tree/develop/packages/plugins/documentation
150-
[12]: https://github.com/strapi/strapi/tree/main/packages/providers/upload-aws-s3
150+
[12]: https://github.com/trieb-work/strapi-provider-cloudflare-r2
151151
[13]: https://github.com/strapi/strapi/tree/develop/packages/plugins/color-picker
152152
[14]: https://github.com/Zaydme/strapi-plugin-multi-select
153153
[15]: https://github.com/Arshiash80/strapi-plugin-iconhub

config/middlewares.ts

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
1-
export default ({ env }) => [
2-
'strapi::logger',
3-
'strapi::errors',
4-
{
5-
name: 'strapi::security',
6-
config: {
7-
contentSecurityPolicy: {
8-
useDefaults: true,
9-
directives: {
10-
'connect-src': ["'self'", 'https:'],
11-
'script-src': [
12-
"'self'",
13-
'unsafe-inline',
14-
'https://*.basemaps.cartocdn.com',
15-
'https://cdn.ckeditor.com',
16-
],
17-
'img-src': [
18-
"'self'",
19-
'data:',
20-
'blob:',
21-
'market-assets.strapi.io',
22-
'your_id.r2.cloudflarestorage.com',
23-
'https://tile.openstreetmap.org',
24-
'https://*.tile.openstreetmap.org',
25-
'https://*.basemaps.cartocdn.com',
26-
],
27-
'media-src': [
28-
"'self'",
29-
'data:',
30-
'blob:',
31-
'market-assets.strapi.io',
32-
'https://*.tile.openstreetmap.org',
33-
'https://unpkg.com/leaflet@1.9.4/dist/images/',
34-
'https://*.basemaps.cartocdn.com',
35-
new URL(env('STORAGE_URL'), 'http://localhost:1337').origin,
36-
],
1+
export default ({ env }) => {
2+
const OS_CDN_HOST = new URL(
3+
env('CLOUDFLARE_PUBLIC_ACCESS_URL'),
4+
'http://localhost:1337',
5+
).origin;
6+
7+
return [
8+
'strapi::logger',
9+
'strapi::errors',
10+
{
11+
name: 'strapi::security',
12+
config: {
13+
contentSecurityPolicy: {
14+
useDefaults: true,
15+
directives: {
16+
'connect-src': ["'self'", 'https:'],
17+
'script-src': [
18+
"'self'",
19+
'unsafe-inline',
20+
'https://*.basemaps.cartocdn.com',
21+
'https://cdn.ckeditor.com',
22+
],
23+
'img-src': [
24+
"'self'",
25+
'data:',
26+
'blob:',
27+
'market-assets.strapi.io',
28+
OS_CDN_HOST,
29+
'https://tile.openstreetmap.org',
30+
'https://*.tile.openstreetmap.org',
31+
'https://*.basemaps.cartocdn.com',
32+
],
33+
'media-src': [
34+
"'self'",
35+
'data:',
36+
'blob:',
37+
'market-assets.strapi.io',
38+
'https://*.tile.openstreetmap.org',
39+
'https://unpkg.com/leaflet@1.9.4/dist/images/',
40+
'https://*.basemaps.cartocdn.com',
41+
OS_CDN_HOST,
42+
],
43+
},
3744
},
3845
},
3946
},
40-
},
41-
'strapi::cors',
42-
'strapi::poweredBy',
43-
'strapi::query',
44-
'strapi::body',
45-
'strapi::session',
46-
'strapi::favicon',
47-
'strapi::public',
48-
];
47+
'strapi::cors',
48+
'strapi::poweredBy',
49+
'strapi::query',
50+
'strapi::body',
51+
'strapi::session',
52+
'strapi::favicon',
53+
'strapi::public',
54+
];
55+
};

config/plugins.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
export default ({ env }) => ({
22
upload: {
33
config: {
4-
provider: 'aws-s3',
4+
provider: 'strapi-provider-cloudflare-r2',
55
providerOptions: {
6-
credentials: {
7-
accessKeyId: env('CLOUDFLARE_ACCESS_KEY_ID'),
8-
secretAccessKey: env('CLOUDFLARE_ACCESS_SECRET'),
9-
},
10-
region: 'auto',
6+
accessKeyId: env('CLOUDFLARE_ACCESS_KEY_ID'),
7+
secretAccessKey: env('CLOUDFLARE_ACCESS_SECRET'),
118
endpoint: env('CLOUDFLARE_ENDPOINT'),
129
params: {
1310
Bucket: env('CLOUDFLARE_BUCKET'),
1411
},
12+
cloudflarePublicAccessUrl: env('CLOUDFLARE_PUBLIC_ACCESS_URL'),
1513
},
1614
},
1715
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"@strapi/plugin-color-picker": "~5.15.0",
1414
"@strapi/plugin-documentation": "~5.15.0",
1515
"@strapi/plugin-users-permissions": "~5.15.0",
16-
"@strapi/provider-upload-aws-s3": "^5.15.0",
1716
"@strapi/strapi": "~5.15.0",
1817
"better-sqlite3": "^11.10.0",
1918
"cross-env": "^7.0.3",
@@ -24,6 +23,7 @@
2423
"react-router-dom": "^6.30.0",
2524
"strapi-location-picker": "^0.0.1",
2625
"strapi-plugin-multi-select": "^2.1.1",
26+
"strapi-provider-cloudflare-r2": "^0.3.0",
2727
"styled-components": "^6.1.18"
2828
},
2929
"devDependencies": {

0 commit comments

Comments
 (0)