diff --git a/src/http-api/index.ts b/src/http-api/index.ts index 346a9e54991..a556ced9413 100644 --- a/src/http-api/index.ts +++ b/src/http-api/index.ts @@ -73,8 +73,9 @@ export class MatrixHttpApi extends FetchHttpApi { uploadResolvers.reject(new Error("Timeout")); }; - // set an initial timeout of 30s; we'll advance it each time we get a progress notification - let timeoutTimer = callbacks.setTimeout(timeoutFn, 30000); + // set an initial timeout (default to 30s); extendable via opts.timeoutMs + const timeoutDuration = opts.timeoutMs ?? 30000; + let timeoutTimer = callbacks.setTimeout(timeoutFn, timeoutDuration); xhr.onreadystatechange = function (): void { switch (xhr.readyState) { @@ -108,7 +109,7 @@ export class MatrixHttpApi extends FetchHttpApi { callbacks.clearTimeout(timeoutTimer); upload.loaded = ev.loaded; upload.total = ev.total; - timeoutTimer = callbacks.setTimeout(timeoutFn, 30000); + timeoutTimer = callbacks.setTimeout(timeoutFn, timeoutDuration); opts.progressHandler?.({ loaded: ev.loaded, total: ev.total, diff --git a/src/http-api/interface.ts b/src/http-api/interface.ts index 40100a5b552..70bac40c8f3 100644 --- a/src/http-api/interface.ts +++ b/src/http-api/interface.ts @@ -207,6 +207,11 @@ export interface UploadOpts { */ progressHandler?(progress: UploadProgress): void; abortController?: AbortController; + /** + * Optional. Timeout in milliseconds before the upload is aborted. + * Defaults to 30000 (30 seconds) if not specified. + */ + timeoutMs?: number; } export interface Upload {