Multipart/form-data support in fetch

Back to Bug Reports
An issue has been acknowledged in this thread and it is being tracked internally by the Fuse team.

In order to send multipart/form-data in a post request, the github docs for fetch suggest the following:

var formData = new FormData();
formData.append('field1', 'field1value');
etc...

However, the above results in ReferenceError: FormData is not defined.

Is there a workaround for this until multipart/form-data is supported?

Thank, Levi

I don't know of any workarounds off the top of my head, but I've raised an issue internally to get this supported ASAP at least.

Hi,

i also facing the same issue where as my server required me to send csrf token, and it will only allowed if i use multipart/form-data instead of application/json for Content-Type.

Jake Taylor wrote:

I don't know of any workarounds off the top of my head, but I've raised an issue internally to get this supported ASAP at least.

any news on this issue?

We have not started on this yet. ArrayBuffer support is coming first, then we can look at FormData, thanks for your patiance. You can write something manually from the Uno side if you are stuck.

Hi guys,

A workaround I discovered is using XMLHttpRequest.

Following is the working codeblock at my end.

var xhr = new XMLHttpRequest();
var params = "var1=val1&var2=val2";
xhr.open("POST", "<API END POINT>" , true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
    // JSON.parse does not evaluate the attacker's scripts.
    var resp = JSON.parse(xhr.responseText);
    console.log(resp.status);
  }
}
xhr.send(params);

That would be amazing! Would make integration with many backends much much easier. Would be up for testing if you need to. Thanks for amazing work

Any updates on FormData, or any other alternative way to upload a file?

Don't want to waste time building a custom request manually if there is a solution already available. Please share update/timeline for this capability.

Post Stats
  • 14
    replies
  • 3506
    views
  • 5
    users
Frequent Posters