Skip to content

Comments

Fix: file downloads fail with 401 when basic auth is enabled#125

Open
G4brym wants to merge 1 commit intomainfrom
fix/issue-63
Open

Fix: file downloads fail with 401 when basic auth is enabled#125
G4brym wants to merge 1 commit intomainfrom
fix/issue-63

Conversation

@G4brym
Copy link
Owner

@G4brym G4brym commented Feb 20, 2026

Summary

Fixes #63

  • File downloads from the right-click context menu failed with 401 when basic auth was enabled
  • The downloadObject() method created a raw <a> element pointing directly at the API URL — browser-initiated downloads via <a> links don't include custom HTTP headers, so the Authorization: Basic header was never sent
  • Chrome enforces this strictly; Safari is more lenient, which explains the browser difference reported in the issue

Changes

  • Replaced the direct <a> link download with an authenticated fetch using apiHandler.downloadFile() (which goes through the Axios instance with auth headers)
  • Creates a temporary blob URL for the browser to download
  • Added error handling with user notification on failure

Test plan

  • Enable basic auth on R2-Explorer
  • Right-click a file → Download → verify it downloads successfully in Chrome
  • Verify downloads still work without auth enabled
  • Verify large file downloads work correctly (blob approach)

🤖 Generated with Claude Code

When basic auth is enabled, the downloadObject method in FileContextMenu
created a direct <a> link to the API endpoint. Browser-initiated downloads
via <a> links do not include custom Authorization headers, causing 401
errors (especially in Chrome).

This changes the download to use apiHandler.downloadFile() which goes
through the Axios instance with proper auth headers already configured,
then creates a temporary blob URL for the browser download.

Fixes #63
@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
r2-explorer-docs 015693e Commit Preview URL

Branch Preview URL
Feb 20 2026, 08:57 AM

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.

unable to download

1 participant