Multipart/form-data support in fetch

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?

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.

+1 for FormData.

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);

Any idea of a timeline for FormData support?

I will see if I can start on it this week, can’t promise anything though.

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.

Any news about FormData? :slight_smile: I think fetch is cleaner than XMLHttpRequest.

Edit: It was a problem with tokens and laravel :stuck_out_tongue:

This post seems somewhat relevant: https://www.fusetools.com/community/forums/howto_discussions/how_do_i_receive_post_data_in_php_sent_from_fuse-j?page=1&highlight=3c900499-38e3-4a26-867e-40a09ed21669#post-3c900499-38e3-4a26-867e-40a09ed21669

@jesusmartinoza We have not been able to complete FormData yet. But you can upload a binary this way and here is a community version of how to do multipart upload.

It would be reall great to complete the FormData in next version of Fuse! +1

+1

+1

+1

Anders Bondehagen wrote:
I will see if I can start on it this week, can’t promise anything though.

Good thing that you didn’t promise anything, a year later and no update. :slight_smile: but the workaround posted by linked by Anders works fine.

+1