Skip to content

Commit

Permalink
Enable chunking for bigger files in web upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Oct 7, 2016
1 parent 5cc4496 commit bcc901d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
25 changes: 20 additions & 5 deletions apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ OC.FileUpload.prototype = {
this.data.headers['X-OC-Mtime'] = file.lastModified / 1000;
}

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

var uid = OC.getCurrentUser().uid;
return this.uploader.filesClient.move(
return this.uploader.davClient.move(
'uploads/' + encodeURIComponent(uid) + '/' + encodeURIComponent(this.getId()) + '/.file',
'files/' + encodeURIComponent(uid) + '/' + OC.joinPaths(this.getFullPath(), this.getFileName())
);
Expand All @@ -276,7 +276,7 @@ OC.FileUpload.prototype = {
abort: function() {
if (this.data.isChunked) {
// delete transfer directory for this upload
this.uploader.filesClient.remove(
this.uploader.davClient.remove(
'uploads/' + encodeURIComponent(OC.getCurrentUser().uid) + '/' + encodeURIComponent(this.getId())
);
}
Expand Down Expand Up @@ -379,6 +379,13 @@ OC.Uploader.prototype = _.extend({
*/
filesClient: null,

/**
* Webdav client pointing at the root "dav" endpoint
*
* @type OC.Files.Client
*/
davClient: null,

/**
* Function that will allow us to know if Ajax uploads are supported
* @link https://github.com/New-Bamboo/example-ajax-upload/blob/master/public/index.html
Expand Down Expand Up @@ -737,6 +744,13 @@ OC.Uploader.prototype = _.extend({

this.fileList = options.fileList;
this.filesClient = options.filesClient || OC.Files.getClient();
this.davClient = new OC.Files.Client({
host: this.filesClient.getHost(),
root: OC.linkToRemoteBase('dav'),
useHTTPS: OC.getProtocol() === 'https',
userName: this.filesClient.getUserName(),
password: this.filesClient.getPassword()
});

$uploadEl = $($uploadEl);
this.$uploadEl = $uploadEl;
Expand All @@ -750,6 +764,7 @@ OC.Uploader.prototype = _.extend({
type: 'PUT',
dropZone: options.dropZone, // restrict dropZone to content div
autoUpload: false,
maxChunkSize: 10 * 1000 * 1000, // 10 MB
sequentialUploads: true,
//singleFileUploads is on by default, so the data.files array will always have length 1
/**
Expand Down
12 changes: 11 additions & 1 deletion core/js/files/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
}

url += options.host + this._root;
this._host = options.host;
this._defaultHeaders = options.defaultHeaders || {
'X-Requested-With': 'XMLHttpRequest',
'requesttoken': OC.requestToken
Expand Down Expand Up @@ -749,6 +750,16 @@
*/
getBaseUrl: function() {
return this._client.baseUrl;
},

/**
* Returns the host
*
* @since 9.2
* @return {String} base URL
*/
getHost: function() {
return this._host;
}
};

Expand Down Expand Up @@ -786,7 +797,6 @@

var client = new OC.Files.Client({
host: OC.getHost(),
port: OC.getPort(),
root: OC.linkToRemoteBase('webdav'),
useHTTPS: OC.getProtocol() === 'https'
});
Expand Down

0 comments on commit bcc901d

Please sign in to comment.