Not getting R2 file contents body from inside Worker
I can download a file from the console, so I can confirm the contents are there. From the shown worker code I do get back a file object, it just doesn't have a body. Any ideas? Thank you for any pointers...
const content = await c.env.DEVME.get(fileName);
if(!content) {
return c.json({error: "File not found"});
}
return c.json(
{
Url: c.req.url,
FileName: fileName,
Content: content,
ContentBody: content.body,
}
);
outputs ...
{
"Url": "https://domain/19512",
"FileName": "domain/19512.json",
"Content": {
"storageClass": "Standard",
"range": {
"offset": 0,
"length": 2868
},
"customMetadata": {},
"httpMetadata": {
"contentType": "application/json"
},
"uploaded": "2024-09-10T01:18:38.267Z",
"checksums": {
"md5": "2f4654a-----fd9c0f6062f7"
},
"httpEtag": ""2f4654-----fd9c0f6062f7"",
"etag": "2f4654a06-----9c0f6062f7",
"size": 2868,
"version": "7e6e267-----69c651e3fde",
"key": "domain/19512.json"
},
"ContentBody": {}
}
1 Reply
I found the answer - I have to read from the content stream. Clue found in this answer -> https://github.com/cloudflare/workers-sdk/issues/6425
GitHub
🐛 BUG: R2ObjectBody body
ReadableStream
not valid for put paramet...Which Cloudflare product(s) does this pertain to? R2 What version(s) of the tool(s) are you using? 3.20240725.0 What version of Node are you using? 20.13.1 What operating system and version are you...