mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
Allow ArrayBuffer and related views as data
In order to push binary data under the form of ArrayBuffer and its related views (Int8Array, ...) one needs not to stringify those. For the XHR adapter there is nothing to do as it natively supports ArrayBuffer in req.send(). Node's http adapter supports only string or Buffer thus a transformation to Buffer is required before setting content length header.
This commit is contained in:
+10
-4
@@ -11,10 +11,16 @@ var CONTENT_TYPE_APPLICATION_JSON = {
|
||||
|
||||
module.exports = {
|
||||
transformRequest: [function (data) {
|
||||
return utils.isObject(data) &&
|
||||
!utils.isFile(data) &&
|
||||
!utils.isBlob(data) ?
|
||||
JSON.stringify(data) : data;
|
||||
if (utils.isArrayBuffer(data)) {
|
||||
return data;
|
||||
}
|
||||
if (utils.isArrayBufferView(data)) {
|
||||
return data.buffer;
|
||||
}
|
||||
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
return data;
|
||||
}],
|
||||
|
||||
transformResponse: [function (data) {
|
||||
|
||||
Reference in New Issue
Block a user