From f0b0c584d650ddb42873f658a480d2fb330eef01 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 5 May 2020 09:10:47 +0200 Subject: [PATCH] Add TUS creation-with-upload support Whenever the server advertised the capability for creation-with-upload, use it automatically for chunked uploads. It is possible to override this and disable it by setting uploadChunkDirect=false in config.json --- apps/files/src/mixins.js | 14 ++++++++++++-- apps/files/src/store/actions.js | 2 +- src/plugins/upload.js | 1 + src/store/config.js | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/files/src/mixins.js b/apps/files/src/mixins.js index af11beb84e1..2a3a3b1909e 100644 --- a/apps/files/src/mixins.js +++ b/apps/files/src/mixins.js @@ -446,7 +446,16 @@ export default { relativePath = pathUtil.join(basePath, relativePath) // FIXME: this might break if relativePath is not the currentFolder // and is a mount point that has no chunk support - if (this.browserSupportsChunked && this.currentFolder.isChunkedUploadSupported) { + if (this.browserSupportsChunked && this.currentFolder.chunkUploadSupport) { + const extraOptions = {} + // enable direct upload if enabled and supported + // instead of create + upload in two requests + if ( + this.configuration.uploadChunkDirect && + this.currentFolder.chunkUploadSupport.extension.includes('creation-with-upload') + ) { + extraOptions.uploadDataDuringCreation = true + } let chunkSize = this.configuration.uploadChunkSize if (this.capabilities.files.tus_support.max_chunk_size > 0) { if ( @@ -463,7 +472,8 @@ export default { overridePatchMethod: !!this.capabilities.files.tus_support.http_method_override, emitProgress: progress => { this.$_ocUpload_onProgress(progress, file) - } + }, + ...extraOptions }) }) } else { diff --git a/apps/files/src/store/actions.js b/apps/files/src/store/actions.js index c284a4639bc..5ba2df13653 100644 --- a/apps/files/src/store/actions.js +++ b/apps/files/src/store/actions.js @@ -94,7 +94,7 @@ function _buildFile(file) { isReceivedShare: function() { return this.permissions.indexOf('S') >= 0 }, - isChunkedUploadSupported: !!(file.getTusSupport && file.getTusSupport()) + chunkUploadSupport: !!file.getTusSupport && file.getTusSupport() } } diff --git a/src/plugins/upload.js b/src/plugins/upload.js index 47253e770f3..37e5ffcad17 100644 --- a/src/plugins/upload.js +++ b/src/plugins/upload.js @@ -27,6 +27,7 @@ export default { removeFingerprintOnSuccess: true, overridePatchMethod: !!options.overridePatchMethod, retryDelays: [0, 3000, 5000, 10000, 20000], + uploadDataDuringCreation: options.uploadDataDuringCreation || false, metadata: { filename: file.name, filetype: file.type, diff --git a/src/store/config.js b/src/store/config.js index 02df0b1224e..b5248dd037c 100644 --- a/src/store/config.js +++ b/src/store/config.js @@ -48,6 +48,7 @@ const mutations = { state.openIdConnect = config.openIdConnect state.rootFolder = config.rootFolder === undefined ? '/' : config.rootFolder state.uploadChunkSize = config.uploadChunkSize === undefined ? Infinity : config.uploadChunkSize + state.uploadChunkDirect = config.uploadChunkDirect !== false // defaults to true if undefined state.state = config.state === undefined ? 'working' : config.state state.applications = config.applications === undefined ? [] : config.applications if (config.corrupted) state.corrupted = config.corrupted