Skip to content

Commit bcc901d

Browse files
author
Vincent Petry
committed
Enable chunking for bigger files in web upload
1 parent 5cc4496 commit bcc901d

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
@@ -224,8 +224,8 @@ OC.FileUpload.prototype = {
224224
this.data.headers['X-OC-Mtime'] = file.lastModified / 1000;
225225
}
226226

227-
var userName = this.uploader.filesClient.getUserName();
228-
var password = this.uploader.filesClient.getPassword();
227+
var userName = this.uploader.davClient.getUserName();
228+
var password = this.uploader.davClient.getPassword();
229229
if (userName) {
230230
// copy username/password from DAV client
231231
this.data.headers['Authorization'] =
@@ -238,7 +238,7 @@ OC.FileUpload.prototype = {
238238
&& this.getFile().size > this.uploader.fileUploadParam.maxChunkSize
239239
) {
240240
data.isChunked = true;
241-
chunkFolderPromise = this.uploader.filesClient.createDirectory(
241+
chunkFolderPromise = this.uploader.davClient.createDirectory(
242242
'uploads/' + encodeURIComponent(OC.getCurrentUser().uid) + '/' + encodeURIComponent(this.getId())
243243
);
244244
// TODO: if fails, it means same id already existed, need to retry
@@ -264,7 +264,7 @@ OC.FileUpload.prototype = {
264264
}
265265

266266
var uid = OC.getCurrentUser().uid;
267-
return this.uploader.filesClient.move(
267+
return this.uploader.davClient.move(
268268
'uploads/' + encodeURIComponent(uid) + '/' + encodeURIComponent(this.getId()) + '/.file',
269269
'files/' + encodeURIComponent(uid) + '/' + OC.joinPaths(this.getFullPath(), this.getFileName())
270270
);
@@ -276,7 +276,7 @@ OC.FileUpload.prototype = {
276276
abort: function() {
277277
if (this.data.isChunked) {
278278
// delete transfer directory for this upload
279-
this.uploader.filesClient.remove(
279+
this.uploader.davClient.remove(
280280
'uploads/' + encodeURIComponent(OC.getCurrentUser().uid) + '/' + encodeURIComponent(this.getId())
281281
);
282282
}
@@ -379,6 +379,13 @@ OC.Uploader.prototype = _.extend({
379379
*/
380380
filesClient: null,
381381

382+
/**
383+
* Webdav client pointing at the root "dav" endpoint
384+
*
385+
* @type OC.Files.Client
386+
*/
387+
davClient: null,
388+
382389
/**
383390
* Function that will allow us to know if Ajax uploads are supported
384391
* @link https://github.com/New-Bamboo/example-ajax-upload/blob/master/public/index.html
@@ -737,6 +744,13 @@ OC.Uploader.prototype = _.extend({
737744

738745
this.fileList = options.fileList;
739746
this.filesClient = options.filesClient || OC.Files.getClient();
747+
this.davClient = new OC.Files.Client({
748+
host: this.filesClient.getHost(),
749+
root: OC.linkToRemoteBase('dav'),
750+
useHTTPS: OC.getProtocol() === 'https',
751+
userName: this.filesClient.getUserName(),
752+
password: this.filesClient.getPassword()
753+
});
740754

741755
$uploadEl = $($uploadEl);
742756
this.$uploadEl = $uploadEl;
@@ -750,6 +764,7 @@ OC.Uploader.prototype = _.extend({
750764
type: 'PUT',
751765
dropZone: options.dropZone, // restrict dropZone to content div
752766
autoUpload: false,
767+
maxChunkSize: 10 * 1000 * 1000, // 10 MB
753768
sequentialUploads: true,
754769
//singleFileUploads is on by default, so the data.files array will always have length 1
755770
/**

core/js/files/client.js

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

3939
url += options.host + this._root;
40+
this._host = options.host;
4041
this._defaultHeaders = options.defaultHeaders || {
4142
'X-Requested-With': 'XMLHttpRequest',
4243
'requesttoken': OC.requestToken
@@ -749,6 +750,16 @@
749750
*/
750751
getBaseUrl: function() {
751752
return this._client.baseUrl;
753+
},
754+
755+
/**
756+
* Returns the host
757+
*
758+
* @since 9.2
759+
* @return {String} base URL
760+
*/
761+
getHost: function() {
762+
return this._host;
752763
}
753764
};
754765

@@ -786,7 +797,6 @@
786797

787798
var client = new OC.Files.Client({
788799
host: OC.getHost(),
789-
port: OC.getPort(),
790800
root: OC.linkToRemoteBase('webdav'),
791801
useHTTPS: OC.getProtocol() === 'https'
792802
});

0 commit comments

Comments
 (0)