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 ?
const formData = await request.formData();
const rawStream = formData.get("entry-name");
// how to get the string value of rawStream? .toString() yields [Object, object]
const formData = await request.formData();
const rawStream = formData.get("entry-name");
// how to get the string value of rawStream? .toString() yields [Object, object]
10 Replies
James
James16mo ago
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?
joshtwist
joshtwist16mo ago
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?
James
James16mo ago
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
joshtwist
joshtwist16mo ago
ah, we may be on an old date wait, this worker is much newer than that
James
James16mo ago
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?
joshtwist
joshtwist16mo ago
I am just using quick edit right now
James
James16mo ago
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
joshtwist
joshtwist16mo ago
does quick edit use a super old compat date then? What's teh default?
James
James16mo ago
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
joshtwist
joshtwist16mo ago
got it, thanks James