Add upload progress dialog

This commit is contained in:
Johannes Zellner
2020-07-10 19:10:29 +02:00
parent 4564e501d3
commit 779c3ba75b
4 changed files with 66 additions and 18 deletions

View File

@@ -2439,21 +2439,33 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype.filesUpload = function (appId, path, file, callback) {
Client.prototype.filesUpload = function (appId, path, file, progressHandler, callback) {
var fd = new FormData();
fd.append('file', file);
var config = {
headers: { 'Content-Type': undefined },
transformRequest: angular.identity
};
post('/api/v1/apps/' + appId + '/files/' + path, fd, config, function (error, data, status) {
function done(error, data, status) {
if (error) return callback(error);
if (status !== 200) return callback(new ClientError(status, data));
callback(null, data);
});
}
$http({
url: client.apiOrigin + '/api/v1/apps/' + appId + '/files/' + path,
method: 'POST',
data: fd,
transformRequest: angular.identity,
headers: {
'Content-Type': undefined,
Authorization: 'Bearer ' + token
},
uploadEventHandlers: {
progress: function (e) {
progressHandler(e.loaded);
}
}
}).success(defaultSuccessHandler(done)).error(defaultErrorHandler(done));
};
client = new Client();