HomeAbout

formData

What is formData

A way to construct a set of key/value pairs representing form fields and their values.

  • Encoding type of: "multipart/form-data".

formData makes it easy to send data to a server using XMLHttpRequest or the fetch API.

formData is used to send complex data like files and audio:

const formData = new FormData(); formData.append('field_name', audioBlob, 'file_name.mp3'););

Audio can be attached as a Blob or File in-memory.

  • when you record audio directly in the browser, it is stored as a Blob.
let blob = new Blob(recordingFile, { type: "audio/ogg" }); let file = new File([blob], 'recording.ogg'); const data = { "user" : "test", }; const formData = new FormData(); formData.append('files.file', file); formData.append('data', JSON.stringify(data));
AboutContact