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
James2y 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
joshtwistOP2y 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
James2y 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
joshtwistOP2y ago
ah, we may be on an old date wait, this worker is much newer than that
James
James2y 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
joshtwistOP2y ago
I am just using quick edit right now
James
James2y 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
joshtwistOP2y ago
does quick edit use a super old compat date then? What's teh default?
James
James2y 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
joshtwistOP2y ago
got it, thanks James
Want results from more Discord servers?
Add your server