I am trying to use the FormData class to send data to my server with HttpRequest.send(). I need to do a POST request with multiple fields. It should work the same as this Javascript code:
//Upload File
var uploadFile = function(file, tag, callback){
var xhr = new XMLHttpRequest();
xhr.open('POST', "upload/", true);
xhr.onreadystatechange=function()
{
if (xhr.readyState==4 && xhr.status==200)
{
callback();
}
}
var formData = new FormData();
formData.append('file', file);
formData.append('tag', tag);
var csrftoken = $.cookie('csrftoken');
xhr.setRequestHeader("X-CSRFToken", csrftoken);
xhr.send(formData);
};
But FormData doesn't seem to work the same way in Dart. Could someone explain how to do this in Dart, if it is possible?