Skip to content

Commit e26d161

Browse files
authored
@uppy/companion: add COMPANION_TUS_DEFERRED_UPLOAD_LENGTH (#5561)
1 parent e056158 commit e26d161

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

packages/@uppy/companion/KUBERNETES.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ data:
2828
COMPANION_DOMAINS: 'sub1.domain.com,sub2.domain.com,sub3.domain.com'
2929
COMPANION_PROTOCOL: 'YOUR SERVER PROTOCOL'
3030
COMPANION_STREAMING_UPLOAD: true
31+
COMPANION_TUS_DEFERRED_UPLOAD_LENGTH: true
3132
COMPANION_REDIS_URL: redis://:[email protected]:6379
3233
COMPANION_SECRET: 'shh!Issa Secret!'
3334
COMPANION_PREAUTH_SECRET: 'another secret'

packages/@uppy/companion/env_example

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ COMPANION_SELF_ENDPOINT=uppy.xxxx.com
55
COMPANION_HIDE_METRICS=false
66
COMPANION_HIDE_WELCOME=false
77
COMPANION_STREAMING_UPLOAD=true
8+
COMPANION_TUS_DEFERRED_UPLOAD_LENGTH=true
89

910
COMPANION_PROTOCOL=https
1011
COMPANION_DATADIR=/mnt/uppy-server-data

packages/@uppy/companion/src/server/Uploader.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,7 @@ class Uploader {
509509
const tusOptions = {
510510
endpoint: this.options.endpoint,
511511
uploadUrl: this.options.uploadUrl,
512-
uploadLengthDeferred: !isFileStream,
513512
retryDelays: [0, 1000, 3000, 5000],
514-
uploadSize: isFileStream ? this.size : undefined,
515513
chunkSize,
516514
headers: headerSanitize(this.options.headers),
517515
addRequestId: true,
@@ -553,6 +551,16 @@ class Uploader {
553551
},
554552
}
555553

554+
if (this.options.companionOptions.tusDeferredUploadLength && !isFileStream) {
555+
tusOptions.uploadLengthDeferred = true
556+
} else {
557+
if (!this.size) {
558+
reject(new Error('tusDeferredUploadLength needs to be enabled if no file size is provided by the provider'))
559+
}
560+
tusOptions.uploadLengthDeferred = false
561+
tusOptions.uploadSize = this.size
562+
}
563+
556564
this.tus = new tus.Upload(stream, tusOptions)
557565

558566
this.tus.start()

packages/@uppy/companion/src/standalone/helper.js

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ const getConfigFromEnv = () => {
183183
// cookieDomain is kind of a hack to support distributed systems. This should be improved but we never got so far.
184184
cookieDomain: process.env.COMPANION_COOKIE_DOMAIN,
185185
streamingUpload: process.env.COMPANION_STREAMING_UPLOAD ? process.env.COMPANION_STREAMING_UPLOAD === 'true' : undefined,
186+
tusDeferredUploadLength: process.env.COMPANION_TUS_DEFERRED_UPLOAD_LENGTH ? process.env.COMPANION_TUS_DEFERRED_UPLOAD_LENGTH === 'true' : true,
186187
maxFileSize: process.env.COMPANION_MAX_FILE_SIZE ? parseInt(process.env.COMPANION_MAX_FILE_SIZE, 10) : undefined,
187188
chunkSize: process.env.COMPANION_CHUNK_SIZE ? parseInt(process.env.COMPANION_CHUNK_SIZE, 10) : undefined,
188189
clientSocketConnectTimeout: process.env.COMPANION_CLIENT_SOCKET_CONNECT_TIMEOUT

packages/@uppy/companion/test/mockserver.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const defaultEnv = {
1212
COMPANION_HIDE_WELCOME: 'false',
1313

1414
COMPANION_STREAMING_UPLOAD: 'true',
15+
COMPANION_TUS_DEFERRED_UPLOAD_LENGTH: 'true',
1516
COMPANION_ALLOW_LOCAL_URLS: 'false',
1617

1718
COMPANION_PROTOCOL: 'http',

0 commit comments

Comments
 (0)