Skip to content

Commit

Permalink
fix(cloudflare): add region configuration for CF R2 storage
Browse files Browse the repository at this point in the history
This change allows users to specify the Cloudflare R2 region, improving
performance and compliance with data residency requirements.
  • Loading branch information
PatelUtkarsh committed Sep 28, 2024
1 parent f99bf50 commit 7ba3748
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Config Environment Variables:
- cf_account_id: Cloudflare access secret
- cf_secret_key: Cloudflare access secret
- cf_bucket_name: Cloudflare bucket name. e.g. `my-bucket-name`
- cf_region: Cloudflare region (Must be one of: wnam, enam, weur, eeur, apac, auto).
- tinypng_api_key: Get your tinypng API key from https://tinypng.com/developers to compress images before uploading.
- shorturl: If you have proxy to bucket via CloudFlare use that url.

Expand Down
3 changes: 3 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@
<string>2bde6e2cfbbf6e40c6d5983c1c8af221</string>
<key>cf_bucket_name</key>
<string>screenshot</string>
<key>cf_region</key>
<string>apac</string>
<key>cf_secret_key</key>
<string>509100e91677c2eb61e5e94522a17200297d3c8ca448104bb7606c60399b84fc</string>
<key>shorturl</key>
Expand All @@ -388,6 +390,7 @@
<string>cf_account_id</string>
<string>cf_access_key</string>
<string>shorturl</string>
<string>cf_region</string>
</array>
<key>version</key>
<string>1.1</string>
Expand Down
4 changes: 3 additions & 1 deletion upload-s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ def main(wf):
file_path, file_name, content_type = capture()
account_id = os.getenv('cf_account_id')
bucket_name = os.getenv('cf_bucket_name')
region_name = os.getenv('cf_region')
s3 = boto3.client(
service_name='s3',
aws_access_key_id=os.getenv('cf_access_key'),
aws_secret_access_key=os.getenv('cf_secret_key'),
endpoint_url="https://%s.r2.cloudflarestorage.com/%s" %(account_id, bucket_name)
endpoint_url="https://%s.r2.cloudflarestorage.com/%s" %(account_id, bucket_name),
region_name=region_name
)
s3.upload_file(file_path, bucket_name, file_name, ExtraArgs={'ContentType': content_type})
shorturl = os.getenv('shorturl')
Expand Down

0 comments on commit 7ba3748

Please sign in to comment.