Hey guys I'm `PUT`ing into my R2 bucket

Hey guys I'm PUTing into my R2 bucket with some customMetadata -- I can see that the PUT command does return the metaData. But when I refresh the data using LIST -- the returned objects do not contain the customMetadata. I confirmed in R2 dashboard that the object does have the customMetadata. Looks like the LIST method does not retrieve the metadata? I am referencing R2Object.customMetadata. See screenshots of api response to my worker functions
No description
No description
No description
4 Replies
AGill
AGillOP7mo ago
hm ok I see in docs that there is include option for R2ListOptions: https://developers.cloudflare.com/r2/api/workers/workers-api-reference/#r2listoptions
Cloudflare Docs
Workers API reference · Cloudflare R2 docs
The in-Worker R2 API is accessed by binding an R2 bucket to a Worker. The Worker you write can expose external access to buckets via a route or …
AGill
AGillOP7mo ago
actually nvm the default is ['httpMetadata', 'customMetadata'] and I am getting back the fields. The problem is that customMetadata is returning null and so my worker function defaults to empty object
AGill
AGillOP7mo ago
ok got it working. I indeed had to add include: ['customMetadata'] option. But TS is not satified with it 🤷‍♂️
No description
AGill
AGillOP7mo ago
I'm using @cloudflare/workers-types version 4.20240512.0 ok figured it out I was importing types from @cloudflare/workers-types path; I have to import from @cloudflare/workers-types/experimental

Did you find this page helpful?