There's a relatively well-documented
There's a relatively well-documented issue with writing to KV where
metadata
is supposedly optional, but required in the type definition within the cloudflare-typescript
library.
Easy, right? Just pass in a dummy empty metadata
object on your writes to KV! WRONG!!
If you just do that, your value gets stored in KV as an object like { value: XYZ, metadata: {}}
. Not super intuitive, I'd rather just store XYZ. So then I learned:
When passing in metadata
, you actually need to include the Content-Type: multipart/form-metadata
header (image 1, link). The library has some handling for automatically including this header, but it doesn't catch these cases where we're forced to pass in empty metadata ๐
Logical next move is to just pass in the header. Ok cool, easy right? WRONG!
Now I get an error back: {"code":10047,"message":"can not parse value and metadata from multipart request body: 'could not parse multipart request: 'no multipart boundary param in Content-Type''"}
Fair, but I feel I am entering hacky code land and am not exactly sure how to set and use a boundary param within the context of the API. Is it as easy as just passing something like Content-Type: multipart/form-data; boundary=asfghjkl
?
Has anyone run into this issue? If so, how did you fix it? Did you just take the L and take .value
on your GET response from KV, potentially running into issues when this finally gets fixed? Or did you manually pass in a fancy header? Or something else I am forgetting?
Here are some previous issues where people encountered the same thing: https://github.com/cloudflare/cloudflare-go/issues/3911, https://github.com/cloudflare/cloudflare-python/issues/2519

6 Replies
Hi Alison! Thanks for the details in here, what version of cloudflare-typescript are you using?
Hey!! Thanks for the reply -- looks like
4.1.0
Update to 4.5.0, some of these things have been resolved, but I still see some issues with the metadata in the update command so I created this issue https://github.com/cloudflare/cloudflare-typescript/issues/2664
GitHub
Workers KV update command with metadata does not update metadata ยท...
Confirm this is a Typescript library issue and not an underlying Cloudflare API issue This is an issue with the Typescript library Describe the bug When trying to use the Write with optional metada...
So 4.5.0 should work for my use case where I'm not using metadata at all?
Yes, that's been my findings
Let me know if this unblocks you @alison!
Will do ๐