aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2021-05-06 18:26:42 +0200
committerJulius Härtl <jus@bitgrid.net>2023-03-08 14:00:04 +0100
commite23aa8883ec0dff03b973fb0bf690cb8482218cf (patch)
treea0ced21511e1dc90d3bd450ea39d88cda0d729b2 /apps/files/js
parent80e12cf72608b7c5776f02f04da98d7a5968bc73 (diff)
downloadnextcloud-server-e23aa8883ec0dff03b973fb0bf690cb8482218cf.tar.gz
nextcloud-server-e23aa8883ec0dff03b973fb0bf690cb8482218cf.zip
feat(s3): Use multipart upload for chunked uploading
This allows to stream file chunks directly to S3 during upload. Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/files/js')
-rw-r--r--apps/files/js/file-upload.js19
-rw-r--r--apps/files/js/jquery.fileupload.js6
2 files changed, 22 insertions, 3 deletions
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 7d6bde6e0f9..f3a39e5861a 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -269,8 +269,12 @@ OC.FileUpload.prototype = {
&& this.getFile().size > this.uploader.fileUploadParam.maxChunkSize
) {
data.isChunked = true;
+ var headers = {
+ Destination: this.uploader.davClient._buildUrl(this.getTargetDestination())
+ };
+
chunkFolderPromise = this.uploader.davClient.createDirectory(
- 'uploads/' + OC.getCurrentUser().uid + '/' + this.getId()
+ 'uploads/' + OC.getCurrentUser().uid + '/' + this.getId(), headers
);
// TODO: if fails, it means same id already existed, need to retry
} else {
@@ -309,17 +313,22 @@ OC.FileUpload.prototype = {
}
if (size) {
headers['OC-Total-Length'] = size;
-
}
+ headers['Destination'] = this.uploader.davClient._buildUrl(this.getTargetDestination());
return this.uploader.davClient.move(
'uploads/' + uid + '/' + this.getId() + '/.file',
- 'files/' + uid + '/' + OC.joinPaths(this.getFullPath(), this.getFileName()),
+ this.getTargetDestination(),
true,
headers
);
},
+ getTargetDestination: function() {
+ var uid = OC.getCurrentUser().uid;
+ return 'files/' + uid + '/' + OC.joinPaths(this.getFullPath(), this.getFileName());
+ },
+
_deleteChunkFolder: function() {
// delete transfer directory for this upload
this.uploader.davClient.remove(
@@ -1326,6 +1335,10 @@ OC.Uploader.prototype = _.extend({
}
var range = data.contentRange.split(' ')[1];
var chunkId = range.split('/')[0].split('-')[0];
+ // Use a numeric chunk id and set the Destination header on all request for ChunkingV2
+ chunkId = Math.ceil((data.chunkSize+Number(chunkId)) / upload.uploader.fileUploadParam.maxChunkSize);
+ data.headers['Destination'] = self.davClient._buildUrl(upload.getTargetDestination());
+
data.url = OC.getRootPath() +
'/remote.php/dav/uploads' +
'/' + OC.getCurrentUser().uid +
diff --git a/apps/files/js/jquery.fileupload.js b/apps/files/js/jquery.fileupload.js
index 9b382ccae39..da516b15e1c 100644
--- a/apps/files/js/jquery.fileupload.js
+++ b/apps/files/js/jquery.fileupload.js
@@ -733,6 +733,12 @@
promise = dfd.promise(),
jqXHR,
upload;
+
+ // Dynamically adjust the chunk size for Chunking V2 to fit into the 10000 chunk limit
+ if (file.size/mcs > 10000) {
+ mcs = Math.ceil(file.size/10000)
+ }
+
if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) ||
options.data) {
return false;