cloudflareR2bindings: Fixed getItemRaw() #517
Closed
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.
TLDR: Files saved to Cloudflare R2 were not returned correctly by
.getItemRaw()
, this PR fixes that.I tried to save files into Cloudflare R2 from a Cloudflare worker by a binding. Saving was no problem by use of
.setItemRaw()
, the file was added correctly to R2. But getting the item I had weird results:.getItem()
returns a string, e.g. when the file was a pdf, the response was the markup of the pdf as a string. (btw this is because it is calling.text()
, not sure if this is usefull at all).getItemRaw()
returns an empty objectI checked the docs and they do it like this:
In this example above,
object
is of type R2ObjectBody, reference is hereIn the current implementation
object.arrayBuffer()
is returned instead of.body
. I am not exactly sure why the author chose to do that, because:Therefor I changed
getItemRaw()
to return.body
which now returns files correctly.