2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

Add 'progress' config option for monitoring progress events for uploads and downloads.

This commit is contained in:
Davis Barber
2015-07-30 13:54:53 -04:00
parent 8c1694e821
commit 261e41644d
3 changed files with 28 additions and 7 deletions
+10
View File
@@ -11,6 +11,7 @@ var transformData = require('./../helpers/transformData');
var urlIsSameOrigin = require('./../helpers/urlIsSameOrigin');
module.exports = function xhrAdapter(resolve, reject, config) {
// Transform request data
var data = transformData(
config.data,
@@ -100,6 +101,15 @@ module.exports = function xhrAdapter(resolve, reject, config) {
}
}
// Handle progress if needed
if (config.progress) {
if (config.method === 'post' || config.method === 'put') {
request.upload.addEventListener('progress', config.progress);
} else if (config.method === 'get') {
request.addEventListener('progress', config.progress);
}
}
if (utils.isArrayBuffer(data)) {
data = new DataView(data);
}