[self hosting] Support B2 download url like Cloudflare #3510
ahxxm
started this conversation in
Feature requests
Replies: 1 comment 2 replies
-
Related:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
Backblaze B2 offers free egress via Cloudflare,
rclone
, for example, supports listing object keys by API, then download via a--b2-download-url
to avoid fees.This would be helpful for general browsing, sharing, generating embeddings and exporting. On a new model release and on-device rolling-in, this might save server owner a few bucks.
Least-effort Hacks
There are 2 parts: setup Cloudflare worker, pass the domain into server.
Cloudflare worker
Following the repo:
B2_APPLICATION_KEY_ID
,B2_ENDPOINT
,BUCKET_NAME
To patch for CORS
OPTIONS
requests, add the following to beginning offetch(request, env)
:You'll get a domain, let's assume it's
https://example-b2.workers.dev
.To verify it works:
Location
, it's userid+uuid+signatureshttps://example-b2.workers.dev/{userid}/{uuid}
, without signatures because the reverse proxy signs againMuseum
Now that we offload presign to Cloudflare workers, the museum API needs to 307 clients to
{domain}/{objectKey}
, one-line patchThis only affects download.
PoC Result
I'm generating embeddings for recently imported takeouts, the first request to get URL
Location
is simply domain+objectkey as expected, then download requestI can upload images as usual, the presigned url points to B2 bucket directly.
Implementation Considerations
I'll leave this as an exercise for the overwhelmed developers with limited bandwidth.(I don't want to break the presign design, it's just that I'd rather hack around with Golang than Javascript)
Since the existing presign locks with s3client, yet the download URL highly dependents on how reverse proxy is setup, it might be easier to only add explicit support via variable name, e.g.
This is easy to revert as well, user can comment out the settings line and restart server.
Beta Was this translation helpful? Give feedback.
All reactions