-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Open
Labels
Description
📜 Description
The application uses Cloudflare R2 for file uploads via the AWS S3 SDK. The R2 client is initialized with a hardcoded endpoint URL that only works for US/default region buckets. When a bucket is created in the EU region, all upload operations fail because the endpoint URL format is different.
Technical Details :
- The endpoint is hardcoded in libraries/nestjs-libraries/src/upload/r2.uploader.ts (line 26)
- Current endpoint: https://${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com
- Required EU endpoint: https://${CLOUDFLARE_ACCOUNT_ID}.eu.r2.cloudflare.com
- This affects all R2 operations: simple uploads, multipart uploads, presigned URLs, etc.
👟 Reproduction steps
- Set up Cloudflare R2 bucket in EU region:
- Create a Cloudflare R2 bucket with jurisdiction set to "EU"
- Note your Account ID, Access Key, and Secret Access Key
- Configure the application environment variables:
- CLOUDFLARE_ACCOUNT_ID=your_account_id
- CLOUDFLARE_ACCESS_KEY=your_access_key
- CLOUDFLARE_SECRET_ACCESS_KEY=your_secret_key
- CLOUDFLARE_BUCKETNAME=your_eu_bucket_name
- CLOUDFLARE_BUCKET_URL=https://your-public-url.r2.cloudflarestorage.com
- Attempt to upload a file:
- Start the application
- Navigate to any upload functionality (e.g., media upload, profile picture, etc.)
- Select a file and attempt to upload
- Observe the upload fails
- Check the application logs:
- Look for error messages related to R2/S3 operations
- Errors is
NoSuchBucket: The specified bucket does not exist.
👍 Expected behavior
- The file upload should succeed regardless of the bucket region (US, EU, APAC, etc.)
- The S3 client should connect to the correct regional endpoint
- Upload operations (simple upload, multipart upload, presigned URLs) should work correctly
- Users should see a success message and the uploaded file should be accessible
- The application should return the correct file URL
👎 Actual Behavior with Screenshots
- Upload operations fail for EU region buckets
- The S3 client attempts to connect to https://{account_id}.r2.cloudflarestorage.com (default endpoint)
- Connection fails or returns authentication/access errors because the bucket exists on the EU endpoint
- Error messages in console logs show S3/R2 operation failures
- Users see upload error messages or timeouts
- Files are not uploaded to R2
💻 Operating system
Linux
🤖 Node Version
22.20-alpine
📃 Provide any additional context for the Bug.
No response
👀 Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Are you willing to submit PR?
Yes I am willing to submit a PR!