Skip to content

Commit 7ba3748

Browse files
committed
fix(cloudflare): add region configuration for CF R2 storage
This change allows users to specify the Cloudflare R2 region, improving performance and compliance with data residency requirements.
1 parent f99bf50 commit 7ba3748

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Config Environment Variables:
2727
- cf_account_id: Cloudflare access secret
2828
- cf_secret_key: Cloudflare access secret
2929
- cf_bucket_name: Cloudflare bucket name. e.g. `my-bucket-name`
30+
- cf_region: Cloudflare region (Must be one of: wnam, enam, weur, eeur, apac, auto).
3031
- tinypng_api_key: Get your tinypng API key from https://tinypng.com/developers to compress images before uploading.
3132
- shorturl: If you have proxy to bucket via CloudFlare use that url.
3233

info.plist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@
373373
<string>2bde6e2cfbbf6e40c6d5983c1c8af221</string>
374374
<key>cf_bucket_name</key>
375375
<string>screenshot</string>
376+
<key>cf_region</key>
377+
<string>apac</string>
376378
<key>cf_secret_key</key>
377379
<string>509100e91677c2eb61e5e94522a17200297d3c8ca448104bb7606c60399b84fc</string>
378380
<key>shorturl</key>
@@ -388,6 +390,7 @@
388390
<string>cf_account_id</string>
389391
<string>cf_access_key</string>
390392
<string>shorturl</string>
393+
<string>cf_region</string>
391394
</array>
392395
<key>version</key>
393396
<string>1.1</string>

upload-s3.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ def main(wf):
6969
file_path, file_name, content_type = capture()
7070
account_id = os.getenv('cf_account_id')
7171
bucket_name = os.getenv('cf_bucket_name')
72+
region_name = os.getenv('cf_region')
7273
s3 = boto3.client(
7374
service_name='s3',
7475
aws_access_key_id=os.getenv('cf_access_key'),
7576
aws_secret_access_key=os.getenv('cf_secret_key'),
76-
endpoint_url="https://%s.r2.cloudflarestorage.com/%s" %(account_id, bucket_name)
77+
endpoint_url="https://%s.r2.cloudflarestorage.com/%s" %(account_id, bucket_name),
78+
region_name=region_name
7779
)
7880
s3.upload_file(file_path, bucket_name, file_name, ExtraArgs={'ContentType': content_type})
7981
shorturl = os.getenv('shorturl')

0 commit comments

Comments
 (0)