Skip to content

Commit caba170

Browse files
author
Vincent Petry
committed
Enable chunking for bigger files in web upload
1 parent 234a631 commit caba170

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

apps/files/js/file-upload.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ OC.FileUpload.prototype = {
244244
this.data.headers['X-OC-Mtime'] = file.lastModified / 1000;
245245
}
246246

247-
var userName = this.uploader.filesClient.getUserName();
248-
var password = this.uploader.filesClient.getPassword();
247+
var userName = this.uploader.davClient.getUserName();
248+
var password = this.uploader.davClient.getPassword();
249249
if (userName) {
250250
// copy username/password from DAV client
251251
this.data.headers['Authorization'] =
@@ -258,7 +258,7 @@ OC.FileUpload.prototype = {
258258
&& this.getFile().size > this.uploader.fileUploadParam.maxChunkSize
259259
) {
260260
data.isChunked = true;
261-
chunkFolderPromise = this.uploader.filesClient.createDirectory(
261+
chunkFolderPromise = this.uploader.davClient.createDirectory(
262262
'uploads/' + encodeURIComponent(OC.getCurrentUser().uid) + '/' + encodeURIComponent(this.getId())
263263
);
264264
// TODO: if fails, it means same id already existed, need to retry
@@ -284,7 +284,7 @@ OC.FileUpload.prototype = {
284284
}
285285

286286
var uid = OC.getCurrentUser().uid;
287-
return this.uploader.filesClient.move(
287+
return this.uploader.davClient.move(
288288
'uploads/' + encodeURIComponent(uid) + '/' + encodeURIComponent(this.getId()) + '/.file',
289289
'files/' + encodeURIComponent(uid) + '/' + OC.joinPaths(this.getFullPath(), this.getFileName())
290290
);
@@ -296,7 +296,7 @@ OC.FileUpload.prototype = {
296296
abort: function() {
297297
if (this.data.isChunked) {
298298
// delete transfer directory for this upload
299-
this.uploader.filesClient.remove(
299+
this.uploader.davClient.remove(
300300
'uploads/' + encodeURIComponent(OC.getCurrentUser().uid) + '/' + encodeURIComponent(this.getId())
301301
);
302302
}
@@ -399,6 +399,13 @@ OC.Uploader.prototype = _.extend({
399399
*/
400400
filesClient: null,
401401

402+
/**
403+
* Webdav client pointing at the root "dav" endpoint
404+
*
405+
* @type OC.Files.Client
406+
*/
407+
davClient: null,
408+
402409
/**
403410
* Function that will allow us to know if Ajax uploads are supported
404411
* @link https://github.com/New-Bamboo/example-ajax-upload/blob/master/public/index.html
@@ -758,6 +765,13 @@ OC.Uploader.prototype = _.extend({
758765

759766
this.fileList = options.fileList;
760767
this.filesClient = options.filesClient || OC.Files.getClient();
768+
this.davClient = new OC.Files.Client({
769+
host: this.filesClient.getHost(),
770+
root: OC.linkToRemoteBase('dav'),
771+
useHTTPS: OC.getProtocol() === 'https',
772+
userName: this.filesClient.getUserName(),
773+
password: this.filesClient.getPassword()
774+
});
761775

762776
if (options.url) {
763777
this.url = options.url;
@@ -775,6 +789,7 @@ OC.Uploader.prototype = _.extend({
775789
type: 'PUT',
776790
dropZone: options.dropZone, // restrict dropZone to content div
777791
autoUpload: false,
792+
maxChunkSize: 10 * 1000 * 1000, // 10 MB
778793
sequentialUploads: true,
779794
//singleFileUploads is on by default, so the data.files array will always have length 1
780795
/**

core/js/files/client.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
}
3737

3838
url += options.host + this._root;
39+
this._host = options.host;
3940
this._defaultHeaders = options.defaultHeaders || {
4041
'X-Requested-With': 'XMLHttpRequest',
4142
'requesttoken': OC.requestToken
@@ -761,6 +762,16 @@
761762
*/
762763
getBaseUrl: function() {
763764
return this._client.baseUrl;
765+
},
766+
767+
/**
768+
* Returns the host
769+
*
770+
* @since 9.2
771+
* @return {String} base URL
772+
*/
773+
getHost: function() {
774+
return this._host;
764775
}
765776
};
766777

@@ -798,7 +809,6 @@
798809

799810
var client = new OC.Files.Client({
800811
host: OC.getHost(),
801-
port: OC.getPort(),
802812
root: OC.linkToRemoteBase('webdav'),
803813
useHTTPS: OC.getProtocol() === 'https'
804814
});

0 commit comments

Comments
 (0)