What sort of stuff would people want in
What sort of stuff would people want in a “using R2 with Workers” guide/reference? I’m thinking:
- Uploading files, both from requests to the Worker and subrequests
- FormData vs streaming the body
- Retrieving files, including handling httpMetadata and ETags
- Listing files, dealing with pagination using cursors
- Deleting files, using a preshared secret in the request
- Handling range & conditionals
- Using waitUntil for uploads in the event you want to trade off error handling/retries for a faster response to user
https://developers.cloudflare.com/r2/examples/demo-worker/ has the bulk of the “raw” code but I’d like to have individual headings, smaller and more focused code blocks & that opens up the ability to talk a bit more about it in terms of “why” instead of just “how”
24 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
this has support for range and all of the expected goodies: https://github.com/kotx/render/blob/master/src/index.ts
GitHub
render/index.ts at master · kotx/render
Cloudflare Worker to proxy and cache requests to R2 - render/index.ts at master · kotx/render
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
What do you mean? Would you like to see more theoretical documentation for R2 explaining how all of these functions work and why they work the way they do? Because I do agree that would be nice
that's what my original message in this thread was about
Aha!
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
an actual fully fledged guide with individual headings and explanations rather than raw code
Yeah that would be great
handling conditionals is always not-very-fun but the DX around that should be improving
(https://discord.com/channels/595317990191398933/940663374377783388/999766836172312708)
I believe render was mostly made by observing what different clients require for specific functionality (like ranges for
aria2c
multithreaded downloads and media scrubbing) and diving into mdn explanations of how a webserver is supposed to behave and working out how to map that to R2 operations
So something documenting all that and explaining in plain english is definitely a good ideathe docs currently refer you to the HTTP RFC
that's how bad describing conditionals is
they're 'easy' but if you want to keep semantic and do the right response codes depending on which conditional fail then blegh
but miniflare's r2 implementation has all of it now
I believe @kotchu was looking through pages like https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests
HTTP conditional requests - HTTP | MDN
HTTP has a concept of conditional requests, where the result, and even the success of a request, can be changed by comparing the affected resources with the value of a validator. Such requests can be useful to validate the content of a cache, and sparing a useless control, to verify the integrity of a document, like when resuming a download, or ...
so you could probably just c/p it
Which are still quite dense to sift through
that's what the docs opted to do for the s3 extensions (putobject now supports conditionals)
probably easier to consume than RFCs
RFCs are weird
yeah a lot of the mdn articles are just RFCs reformatted for the everyday person to consume
the structure I'd be going for is like how https://developers.cloudflare.com/r2/examples/rclone/ is - compared to https://developers.cloudflare.com/r2/examples/aws-sdk-go/
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
having them split up means you can talk about it without having 20 lines of comments
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View