Skip to main content
it.
1 min read EN
#netlify#functions#formdata#javascript

How to parse FormData values with Netlify Functions V2

I spend 3 hours trying to understand that. All the blog posts related to this topic do not work....

How to parse FormData values with Netlify Functions V2 cover image

I spend 3 hours trying to understand that. All the blog posts related to this topic do not work. Netlify Functions V2 uses Request API. I used Node.js v20 to parse FormData values in multipart/form-data requests. You can see how easy it is with the example below. This function returns form data values as JSON in response.

JavaScript
export default async function (event) {
  const data = await event.formData();
  const fields = {};

  for (const pair of data.entries()) {
    fields[pair[0]] = pair[1];
  }

  return new Response(JSON.stringify(fields), { status: 200 });
}

I hope this helps you. Have nice coding!