Browserify version of Nodejs form-data throws error when appending buffers and streams

Viewed 35

I am trying to create a FormData object in my browserified code. However, it is not working the same way it did in NodeJS. Here is my code:

let body = {
  type: "Introductory",
  answeringRule: { id: "36" },
};

const NodeFormData = require("form-data");
formData = new NodeFormData();

formData.append("json", new Buffer.from(JSON.stringify(body)), {
  filename: "request.json",
  contentType: "application/json",
});

formData.append("binary", audioStream, {
  filename: "audioStream.mp3",
  contentType: "audio/mpeg",
});

In NodeJS this code worked perfectly, appending both the buffer section and the ReadableStream section to the FormData. When I run this in the browserify version, it throws the error:

"Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'."

I am aware that JavaScript has a native FormData constructor as well and I've tried it with both the native version (MDN) and the Browserify NodeJS version and both throw the same error. For my use case I cannot attach these pieces of data as actual Blobs. If I did, then they wouldn't be readable for the next step in the process.

How can I resolve this?

Why doesn't the Browserify version of form-data work the same as the NodeJS version?

0 Answers
Related