postiz-app icon indicating copy to clipboard operation
postiz-app copied to clipboard

Can't retrieve files uploaded to cloudflare

Open mandrade2 opened this issue 6 months ago • 9 comments

Hey I am self hosting and I get an issue when retrieving uploaded content to cloudflare R2. The issue I believe is in this line

https://github.com/gitroomhq/postiz-app/blob/ad21ea0dd3e752a4c0b54f8058c2d02c2e494415/apps/frontend/src/components/media/new.uploader.tsx#L104

I think so because the final url the frontend tries to fetch is like https://xxx.r2.cloudflarestorage.com/asset-id.mp4 but it should actually be https://xxx.r2.cloudflarestorage.com/mybucket/asset-id.mp4. The upload is works fine, i can even see the asset there in the cloudflare UI and postiz does save the asset into it's database. The issue is only when fetching the content in the UI. Haven't yet tried posting.

mandrade2 avatar Jun 18 '25 02:06 mandrade2

I had this issue before and find a way to work around. change your CLOUDFLARE_BUCKET_URL="https://yourR2.com" also from your compose file change this values:

STORAGE_PROVIDER: "cloudflare"
UPLOAD_DIRECTORY: ""
NEXT_PUBLIC_UPLOAD_DIRECTORY: ""

this solution worked well for me.

xlocalx avatar Jul 30 '25 12:07 xlocalx

Hi, I’m running into the same problem. I can’t retrieve the files uploaded to Cloudflare.

I’m self-hosting with Docker Compose via Dokploy, everything runs smoothly and the Cloudflare connection itself works fine. However, when I try to fetch the media I get this error:

"url" parameter is valid but upstream response is invalid

I’ve tried a few fixes, but none worked. Is anyone else experiencing this, or does someone know a potential solution?

r1me75 avatar Aug 28 '25 14:08 r1me75

totally same here

Hi, I’m running into the same problem. I can’t retrieve the files uploaded to Cloudflare.

I’m self-hosting with Docker Compose via Dokploy, everything runs smoothly and the Cloudflare connection itself works fine. However, when I try to fetch the media I get this error:

"url" parameter is valid but upstream response is invalid

I’ve tried a few fixes, but none worked. Is anyone else experiencing this, or does someone know a potential solution?

lvsao avatar Sep 10 '25 15:09 lvsao

Solution: Fix for Cloudflare R2 Image Preview and Posting Issues I encountered the same issue where images uploaded to Cloudflare R2 successfully but failed to display in preview and during posting. After investigation, I found the root cause and solution.

Root Cause The issue was caused by double slashes (//) in the image URL path. When Postiz constructs the image URL, it was generating URLs like: https://yourR2.com//filename.png This caused Next.js Image Optimization to fail with the error: "url" parameter is valid but upstream response is invalid

Solution The fix is simple - ensure there are no trailing slashes in your CLOUDFLARE_BUCKET_URL configuration. Correct Configuration: yamlenvironment: STORAGE_PROVIDER: "cloudflare" UPLOAD_DIRECTORY: "" NEXT_PUBLIC_UPLOAD_DIRECTORY: ""

CLOUDFLARE_ACCOUNT_ID: "your-account-id" CLOUDFLARE_ACCESS_KEY: "your-access-key" CLOUDFLARE_SECRET_ACCESS_KEY: "your-secret-key" CLOUDFLARE_BUCKETNAME: "your-bucket-name" CLOUDFLARE_REGION: "auto" CLOUDFLARE_BUCKET_URL: "https://your-custom-domain.com" # NO trailing slash

Key Points:

Set UPLOAD_DIRECTORY and NEXT_PUBLIC_UPLOAD_DIRECTORY to empty strings Remove any trailing slash from CLOUDFLARE_BUCKET_URL Ensure your R2 bucket has proper CORS configuration

CORS Configuration Make sure your R2 bucket CORS policy includes your domain: json[ { "AllowedOrigins": [ "https://your-postiz-domain.com" ], "AllowedMethods": [ "GET", "POST", "HEAD", "PUT", "DELETE" ], "AllowedHeaders": [ "Authorization", "x-amz-date", "x-amz-content-sha256", "content-type" ], "ExposeHeaders": [ "ETag", "Location" ], "MaxAgeSeconds": 3600 } ] After applying this configuration, both image preview and posting to social media platforms work correctly.

lvsao avatar Sep 10 '25 15:09 lvsao

Solution: Fix for Cloudflare R2 Image Preview and Posting Issues I encountered the same issue where images uploaded to Cloudflare R2 successfully but failed to display in preview and during posting. After investigation, I found the root cause and solution.

Root Cause The issue was caused by double slashes (//) in the image URL path. When Postiz constructs the image URL, it was generating URLs like: https://yourR2.com//filename.png This caused Next.js Image Optimization to fail with the error: "url" parameter is valid but upstream response is invalid

Solution The fix is simple - ensure there are no trailing slashes in your CLOUDFLARE_BUCKET_URL configuration. Correct Configuration: yamlenvironment: STORAGE_PROVIDER: "cloudflare" UPLOAD_DIRECTORY: "" NEXT_PUBLIC_UPLOAD_DIRECTORY: ""

CLOUDFLARE_ACCOUNT_ID: "your-account-id" CLOUDFLARE_ACCESS_KEY: "your-access-key" CLOUDFLARE_SECRET_ACCESS_KEY: "your-secret-key" CLOUDFLARE_BUCKETNAME: "your-bucket-name" CLOUDFLARE_REGION: "auto" CLOUDFLARE_BUCKET_URL: "https://your-custom-domain.com" # NO trailing slash

Key Points:

Set UPLOAD_DIRECTORY and NEXT_PUBLIC_UPLOAD_DIRECTORY to empty strings Remove any trailing slash from CLOUDFLARE_BUCKET_URL Ensure your R2 bucket has proper CORS configuration

CORS Configuration Make sure your R2 bucket CORS policy includes your domain: json[ { "AllowedOrigins": [ "https://your-postiz-domain.com" ], "AllowedMethods": [ "GET", "POST", "HEAD", "PUT", "DELETE" ], "AllowedHeaders": [ "Authorization", "x-amz-date", "x-amz-content-sha256", "content-type" ], "ExposeHeaders": [ "ETag", "Location" ], "MaxAgeSeconds": 3600 } ] After applying this configuration, both image preview and posting to social media platforms work correctly.

Did the proposed solution but did not work? @qiurufeng

r1me75 avatar Sep 10 '25 18:09 r1me75

Solution: Fix for Cloudflare R2 Image Preview and Posting Issues I encountered the same issue where images uploaded to Cloudflare R2 successfully but failed to display in preview and during posting. After investigation, I found the root cause and solution.

Root Cause The issue was caused by double slashes (//) in the image URL path. When Postiz constructs the image URL, it was generating URLs like: https://yourR2.com//filename.png This caused Next.js Image Optimization to fail with the error: "url" parameter is valid but upstream response is invalid

Solution The fix is simple - ensure there are no trailing slashes in your CLOUDFLARE_BUCKET_URL configuration. Correct Configuration: yamlenvironment: STORAGE_PROVIDER: "cloudflare" UPLOAD_DIRECTORY: "" NEXT_PUBLIC_UPLOAD_DIRECTORY: ""

CLOUDFLARE_ACCOUNT_ID: "your-account-id" CLOUDFLARE_ACCESS_KEY: "your-access-key" CLOUDFLARE_SECRET_ACCESS_KEY: "your-secret-key" CLOUDFLARE_BUCKETNAME: "your-bucket-name" CLOUDFLARE_REGION: "auto" CLOUDFLARE_BUCKET_URL: "https://your-custom-domain.com" # NO trailing slash

Key Points:

Set UPLOAD_DIRECTORY and NEXT_PUBLIC_UPLOAD_DIRECTORY to empty strings Remove any trailing slash from CLOUDFLARE_BUCKET_URL Ensure your R2 bucket has proper CORS configuration

CORS Configuration Make sure your R2 bucket CORS policy includes your domain: json[ { "AllowedOrigins": [ "https://your-postiz-domain.com" ], "AllowedMethods": [ "GET", "POST", "HEAD", "PUT", "DELETE" ], "AllowedHeaders": [ "Authorization", "x-amz-date", "x-amz-content-sha256", "content-type" ], "ExposeHeaders": [ "ETag", "Location" ], "MaxAgeSeconds": 3600 } ] After applying this configuration, both image preview and posting to social media platforms work correctly.

Tried this didnt work, Also deleting the media only deletes it from the database and not from cloudflare, i have to manually delete it.

suren19113 avatar Oct 17 '25 10:10 suren19113