Skip to content

Commit 89e2e83

Browse files
committed
Use multipart upload in the web ui
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 43f2858 commit 89e2e83

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

apps/files/js/file-upload.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,12 @@ OC.FileUpload.prototype = {
258258
&& this.getFile().size > this.uploader.fileUploadParam.maxChunkSize
259259
) {
260260
data.isChunked = true;
261+
var headers = (OC.getCapabilities().dav.chunking === '2.0') ? {
262+
'X-Chunking-Destination': this.getTargetDestination()
263+
} : {};
264+
261265
chunkFolderPromise = this.uploader.davClient.createDirectory(
262-
'uploads/' + OC.getCurrentUser().uid + '/' + this.getId()
266+
'uploads/' + OC.getCurrentUser().uid + '/' + this.getId(), headers
263267
);
264268
// TODO: if fails, it means same id already existed, need to retry
265269
} else {
@@ -298,17 +302,24 @@ OC.FileUpload.prototype = {
298302
}
299303
if (size) {
300304
headers['OC-Total-Length'] = size;
301-
305+
}
306+
if (OC.getCapabilities().dav.chunking === '2.0') {
307+
headers['X-Chunking-Destination'] = this.getTargetDestination();
302308
}
303309

304310
return this.uploader.davClient.move(
305311
'uploads/' + uid + '/' + this.getId() + '/.file',
306-
'files/' + uid + '/' + OC.joinPaths(this.getFullPath(), this.getFileName()),
312+
this.getTargetDestination(),
307313
true,
308314
headers
309315
);
310316
},
311317

318+
getTargetDestination: function() {
319+
var uid = OC.getCurrentUser().uid;
320+
return 'files/' + uid + '/' + OC.joinPaths(this.getFullPath(), this.getFileName())
321+
},
322+
312323
_deleteChunkFolder: function() {
313324
// delete transfer directory for this upload
314325
this.uploader.davClient.remove(
@@ -1133,7 +1144,6 @@ OC.Uploader.prototype = _.extend({
11331144

11341145
if (options.maxChunkSize) {
11351146
this.fileUploadParam.maxChunkSize = options.maxChunkSize;
1136-
}
11371147

11381148
// initialize jquery fileupload (blueimp)
11391149
var fileupload = this.$uploadEl.fileupload(this.fileUploadParam);
@@ -1274,6 +1284,12 @@ OC.Uploader.prototype = _.extend({
12741284
var upload = self.getUpload(data);
12751285
var range = data.contentRange.split(' ')[1];
12761286
var chunkId = range.split('/')[0].split('-')[0];
1287+
if (OC.getCapabilities().dav.chunking === '2.0') {
1288+
// Calculate chunk index for usage with s3
1289+
chunkId = Math.ceil((data.chunkSize+Number(chunkId)) / upload.uploader.fileUploadParam.maxChunkSize);
1290+
data.headers['X-Chunking-Destination'] = upload.getTargetDestination();
1291+
}
1292+
12771293
data.url = OC.getRootPath() +
12781294
'/remote.php/dav/uploads' +
12791295
'/' + OC.getCurrentUser().uid +

apps/files/js/jquery.fileupload.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,12 @@
733733
promise = dfd.promise(),
734734
jqXHR,
735735
upload;
736+
737+
// Dynamically adjust the chunk size for Chunking V2 to fit into the 10000 chunk limit
738+
if ((OC.getCapabilities().dav.chunking === '2.0') && file.size/mcs > 10000) {
739+
mcs = Math.ceil(file.size/10000)
740+
}
741+
736742
if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) ||
737743
options.data) {
738744
return false;
@@ -1486,4 +1492,4 @@
14861492

14871493
});
14881494

1489-
}));
1495+
}));

core/src/files/client.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ import escapeHTML from 'escape-html'
741741
return promise
742742
},
743743

744-
_simpleCall: function(method, path) {
744+
_simpleCall: function(method, path, headers) {
745745
if (!path) {
746746
throw 'Missing argument "path"'
747747
}
@@ -752,7 +752,8 @@ import escapeHTML from 'escape-html'
752752

753753
this._client.request(
754754
method,
755-
this._buildUrl(path)
755+
this._buildUrl(path),
756+
headers ? headers : {}
756757
).then(
757758
function(result) {
758759
if (self._isSuccessStatus(result.status)) {
@@ -773,8 +774,8 @@ import escapeHTML from 'escape-html'
773774
*
774775
* @returns {Promise}
775776
*/
776-
createDirectory: function(path) {
777-
return this._simpleCall('MKCOL', path)
777+
createDirectory: function(path, headers) {
778+
return this._simpleCall('MKCOL', path, headers)
778779
},
779780

780781
/**

0 commit comments

Comments
 (0)