How to read FormData entry in CloudFlare?
CloudFlare Workers do not support the
Blob
or FileReader
type. How can I read the 'body' of a multipart/form-data post ?
10 Replies
Are you trying to upload files? Workers do support
File
: https://walshy.dev/blog/21_09_10-handling-file-uploads-with-cloudflare-workers
Or perhaps some other kind of data?Yes. Actually, I've spotted the issue. We also use Deno which returns a File object when we call formData.get("entry-name"). However, CloudFlare returns a string which I was not expecting.
Is this by design?
Are you using a modern compatibility date? Prior to 2021-11-03, it returned a string: https://developers.cloudflare.com/workers/platform/compatibility-dates/#formdata-parsing-supports-file
But as long as you're using a modern compat date (newer than 2021-11-03), that should no longer be the case
ah, we may be on an old date
wait, this worker is much newer than that
You can also just enable that specific compat flag
formdata_parser_supports_files
, if you can't bump your compatibility date for whatever reason
What compatability_date
do you have in your wrangler.toml
?I am just using quick edit right now
Oh I see - yeah unfortunately quick edit doesn't specify a compat date so this won't work there
You'll need to use wrangler to publish
does quick edit use a super old compat date then? What's teh default?
It doesn't set one as far as I know, which'll mean it just won't have any breaking changes from since when compat dates were first introduced in 2021
got it, thanks James