Issue with FormData Methods in Cloudflare Workers

I am currently developing an API using Cloudflare Workers and have encountered a technical issue with handling FormData objects. Specifically, I am unable to use the form.getBuffer() and form.getBoundary() methods as they are seemingly not recognized as functions. Here is the relevant part of my code:

const form = new FormData();
form.append("manifest", JSON.stringify(manifest), {
  contentType: "application/json",
  header: {
    "content-type": "application/json; charset=utf-8",
    ...(signature ? { "expo-signature": signature } : {}),
  },
});
form.append("extensions", JSON.stringify({ assetRequestHeaders }), {
  contentType: "application/json",
});

return c.newResponse(form.getBuffer(), {
  status: 200,
  headers: {
    "expo-protocol-version": protocolVersion.toString(),
    "expo-sfv-version": "0",
    "cache-control": "private, max-age=0",
    "content-type": `multipart/mixed; boundary=${form.getBoundary()}`,
  },
});

Upon attempting to execute this, I receive the following errors:

  • TypeError: form.getBuffer is not a function
  • TypeError: form.getBoundary is not a function

Could you please advise on how to correctly implement these methods, or suggest an alternative approach to handle multipart/form-data in Cloudflare Workers? Your guidance on how to properly structure this type of request would be greatly appreciated.

Thank you for your assistance.

Best regards,

Neither of those are standard functions - FormData - Web APIs | MDN

You can pass a FormData into a Response body without turning into an ArrayBuffer - Response: Response() constructor - Web APIs | MDN

As for the boundary, you could parse it from the Content-Type. If you don’t need it to be the exact same though, I’d just let Workers handle it.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.