Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR creates an api endpoint that abstracts object storage and integrates with CloudFlare R2 for uploading and manage all type of files while adding support for returning S3 Presigning URLs, base64, public url and more.
@lane711 and @acoreyj I'd love to hear your thoughts specially because @acoreyj already has a similar PR on the queue. I could mark this as WIP while we discuss the progress of this PR.
What this PR do:
Creates a
/bucket
endpoint that supportsPOST
as anapplication/form-data
that handles a form with field calledfile
representing a file upload.On
POST
the api can customize the return using themethod
query parameter as one of the optionsurl | tempurl | blob | base64 | arrayBuffer | sha1 | text | null
- each one being a type of return explained belowOn
GET
the way to retrieve the object from the bucket is to pass as query string the values ofkey
being the R2 file key name and optionally themethod
parameter like onPOST
On
Delete
the request body has to contain the namefilename
with the R2 Object key so it can be deleted.It works with aws/sdk like the docs says to presign urls and creates the security layer on top of the objects.
On
wrangler.toml
It creates a new binding entry:access_key_id
andsecret_access_key
What this PR dosen't do:
( here I think we could merge the work that @acoreyj did and maybe creates a type of middleware for this request)
Parameters explained
blob | arrayBuffer | text | json | readblestream
According to the docs that is the possible returns from the R2 bucket when we retrieve an existing object from the bucket
sha1 | base64
This are returns created by the API consuming the
arrayBuffer
retrieved by the bucket and then transforming into a more ready-to-go outputtempurl | url
The
tempurl
is the S3 Presign output since this links has an expiry date that can be configured (but right now is set to 1 hour).The
url
is the public URL of the image if the credentials is set on thewrangler.toml
file.Live Example
A live version of this PR can be found here.