Skip to content

Guard download headers for R2 public URLs - #26

Merged
Simplereally merged 2 commits into
mainfrom
copilot/fix-download-icon-error
Jan 21, 2026
Merged

Simplereally merged 2 commits into
mainfrom
copilot/fix-download-icon-error

Conversation

Copilot AI commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Canvas downloads failed because the client always attached Pollinations API auth headers to R2 public URLs, triggering CORS/403 errors. This update makes header usage conditional so R2 downloads succeed without changing the canvas flow.

  • Download fetch routing
    • Detect Pollinations API URLs and only attach Authorization headers for those endpoints.
    • Use plain fetch for R2/public URLs to avoid preflight or auth rejection.
  • Download behavior
    • Preserve existing blob handling and browser download trigger logic.
  • Tests
    • Added coverage in lib/api/image-api.test.ts for Pollinations vs non-Pollinations download header handling.
const headers = isPollinationsUrl(imageUrl)
  ? PollinationsAPI.getHeaders()
  : undefined

const response = await fetch(imageUrl, headers ? { headers } : undefined)
Original prompt

Right now people see an error when ckicking the download icon when hovering over a generated image or video on the canvas. It should be downloading from the r2 storage with no issues.

Please identify the root cause by analyzing the canvas code and sureounding code context to understand the flow of data and apply the minimal best practice fix.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel

vercel Bot commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
bloomstudio Ready Ready Preview, Comment Jan 21, 2026 8:29am

Copilot AI changed the title [WIP] Fix error when clicking download icon on generated media Guard download headers for R2 public URLs Jan 21, 2026
Copilot AI requested a review from Simplereally January 21, 2026 08:20
@Simplereally

Copy link
Copy Markdown
Owner

@copilot Yep sounds reasonable. Document the code as well to explain the fix.

Co-authored-by: Simplereally <120893410+Simplereally@users.noreply.github.com>

Copilot AI commented Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Yep sounds reasonable. Document the code as well to explain the fix.

Added inline documentation explaining the Pollinations-only header guard and updated tests accordingly. Commit: daecddf.

@coderabbitai

coderabbitai Bot commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@Simplereally
Simplereally merged commit 9561b61 into main Jan 21, 2026
3 of 4 checks passed
@Simplereally
Simplereally deleted the copilot/fix-download-icon-error branch January 21, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants