This whole transport mode is currently not using mw.Api, but directly using a XHR. This is unfortunate, because it means it cannot use mw.Api's postWithToken badtoken recovery for instance.
The reason for this implementation was probably because we initially were not able to make this working with jQuery ajax or mw.Api
But I think that:
api.postWithEditToken( {}, {
data: formData,
contentType: false,
processData: false
} )
Then in api.post() we can look for data in the ajaxoptions, do a 'instanceof FormData' check, and then iterate over the params object, and do formData.append( key, value ); (and possibly set the contentType and processData options automatically here).
https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Api-method-postWithToken
https://coderwall.com/p/p-n7eq/file-uploads-with-jquery-html5-and-formdata