Commit edf96f66 authored by Aurel's avatar Aurel

make form data work in node

parent d395a6f5
/*global window, RSVP, Blob, XMLHttpRequest, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array, navigator */
FileReader, ArrayBuffer, Uint8Array, navigator, FormData, StreamBuffers */
(function (window, RSVP, Blob, QueryFactory, Query, atob,
FileReader, ArrayBuffer, Uint8Array, navigator) {
"use strict";
......@@ -42,7 +42,7 @@
function ajax(param) {
var xhr = new XMLHttpRequest();
return new RSVP.Promise(function (resolve, reject, notify) {
var k;
var k, buffer = new StreamBuffers.WritableStreamBuffer();
xhr.open(param.type || "GET", param.url, true);
xhr.responseType = param.dataType || "";
if (typeof param.headers === 'object' && param.headers !== null) {
......@@ -71,7 +71,16 @@
if (typeof param.beforeSend === 'function') {
param.beforeSend(xhr);
}
if (param.data instanceof FormData) {
xhr.setRequestHeader("Content-Type",
"multipart\/form-data; boundary=" + param.data.getBoundary());
param.data.pipe(buffer, {end: false});
param.data.on("end", function () {
xhr.send(buffer.getContents());
});
} else {
xhr.send(param.data);
}
}, function () {
xhr.abort();
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment