diff --git a/packages/@uppy/companion-client/src/RequestClient.ts b/packages/@uppy/companion-client/src/RequestClient.ts index 7d7644a066..1717dc6031 100644 --- a/packages/@uppy/companion-client/src/RequestClient.ts +++ b/packages/@uppy/companion-client/src/RequestClient.ts @@ -479,13 +479,16 @@ export default class RequestClient { break } case 'success': { + // payload.response exists for xhr-upload but not for tus/transloadit + const text = payload.response?.responseText + this.uppy.emit( 'upload-success', this.uppy.getFile(file.id), - // @ts-expect-error event expects a lot more data. - // TODO: add missing data? { uploadURL: payload.url, + status: payload.response?.status ?? 200, + body: text ? JSON.parse(text) : undefined, }, ) socketAbortController?.abort?.() diff --git a/packages/@uppy/companion/src/server/Uploader.js b/packages/@uppy/companion/src/server/Uploader.js index 53d6e71a93..6375b1bdae 100644 --- a/packages/@uppy/companion/src/server/Uploader.js +++ b/packages/@uppy/companion/src/server/Uploader.js @@ -642,8 +642,16 @@ class Uploader { throw new Error(errMsg) } + let bodyURL = null + try { + bodyURL = JSON.parse(response.body)?.url + } catch { + // response.body can be undefined or an empty string + // in that case we ignore and continue. + } + return { - url: null, + url: bodyURL, extraData: { response: getRespObj(response), bytesUploaded }, } } catch (err) {