1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Add progress handler to uploadContent

bluebird doesn't support promise progression (or rather, it does, but it's
heavily deprecated and doesn't use the same API as q), so replace the
(undocumented) promise progression on uploadFile with a callback.
This commit is contained in:
Richard van der Hoff
2017-07-14 16:51:43 +01:00
parent f1c5b632cc
commit 34b31865c5
2 changed files with 14 additions and 1 deletions

View File

@@ -134,6 +134,10 @@ module.exports.MatrixHttpApi.prototype = {
* invoke on success/failure. See the promise return values for more
* information.
*
* @param {Function=} opts.progressHandler Optional. Called when a chunk of
* data has been uploaded, with an object containing the fields `loaded`
* (number of bytes transferred) and `total` (total size, if known).
*
* @return {module:client.Promise} Resolves to response object, as
* determined by this.opts.onlyData, opts.rawResponse, and
* opts.onlyContentUri. Rejects with an error (usually a MatrixError).
@@ -260,7 +264,12 @@ module.exports.MatrixHttpApi.prototype = {
upload.loaded = ev.loaded;
upload.total = ev.total;
xhr.timeout_timer = callbacks.setTimeout(timeout_fn, 30000);
defer.notify(ev);
if (opts.progressHandler) {
opts.progressHandler({
loaded: ev.loaded,
total: ev.total,
});
}
});
let url = this.opts.baseUrl + "/_matrix/media/v1/upload";
url += "?access_token=" + encodeURIComponent(this.opts.accessToken);