Multipart/form-data support in fetch


#1

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


#2

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.


#3

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.


#4

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?


#5

Any news on this issue?


#6

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.


#7

+1 for FormData.


#8

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


#9

Any idea of a timeline for FormData support?


#10

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


#11

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


#12

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.


#13

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:


#14

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


#15

@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.


#16

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


#17

+1


#18

+1


#19

+1


#20

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