Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Attempt at implementing file upload progress #5874

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ function $HttpProvider() {
// if we won't have the response in cache, send the request to the backend
if (isUndefined(cachedResp)) {
$httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
config.withCredentials, config.responseType);
config.withCredentials, config.responseType, notify);
}

return promise;
Expand All @@ -1004,6 +1004,16 @@ function $HttpProvider() {
}


/**
* Callback registered to $httpBackend():
* - propagates xhr events via notify
* - calls $apply
*/
function notify(event) {
deferred.notify(event);
if (!$rootScope.$$phase) $rootScope.$apply();
}

/**
* Resolves the raw $http promise.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
var ABORTED = -1;

// TODO(vojta): fix the signature
return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {
return function(method, url, post, callback, headers, timeout, withCredentials, responseType, notifyCallback) {
var status;
$browser.$$incOutstandingRequestCount();
url = url || $browser.url();
Expand Down Expand Up @@ -97,6 +97,10 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
}
};

xhr.upload.onprogress = function(e) {
notifyCallback(e);
};

if (withCredentials) {
xhr.withCredentials = true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ function MockXhr() {
return lines.join('\n');
};

this.upload = {};

this.abort = angular.noop;
}

Expand Down
2 changes: 2 additions & 0 deletions test/ng/httpBackendSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ describe('$httpBackend', function() {
};

this.getAllResponseHeaders = valueFn('');

this.upload = {};
}

callback.andCallFake(function(status, response) {
Expand Down