diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-12-16 17:35:53 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-10-24 21:45:00 +0200 |
commit | 59c5be1cc572793a8d50e87ab589e1cc4cf2ed12 (patch) | |
tree | 97b096fee075115bac45d69f2e0da7af5ffb41f2 /apps/files_sharing/js | |
parent | 4d01f23978549c2a33e9fdfdc3b9308cc9dc1078 (diff) | |
download | nextcloud-server-59c5be1cc572793a8d50e87ab589e1cc4cf2ed12.tar.gz nextcloud-server-59c5be1cc572793a8d50e87ab589e1cc4cf2ed12.zip |
Use Webdav PUT for uploads in the web browser
- uses PUT method with jquery.fileupload for regular and public file
lists
- for IE and browsers that don't support it, use POST with iframe
transport
- implemented Sabre plugin to handle iframe transport and redirect the
embedded PUT request to the proper handler
- added RFC5995 POST to file collection with "add-member" property to
make it possible to auto-rename conflicting file names
- remove obsolete ajax/upload.php and obsolete ajax routes
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_sharing/js')
-rw-r--r-- | apps/files_sharing/js/public.js | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 0dfff235998..0045c7156d2 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -72,7 +72,8 @@ OCA.Sharing.PublicApp = { folderDropOptions: folderDropOptions, fileActions: fileActions, detailsViewEnabled: false, - filesClient: filesClient + filesClient: filesClient, + enableUpload: true } ); this.files = OCA.Files.Files; @@ -170,6 +171,30 @@ OCA.Sharing.PublicApp = { return OC.generateUrl('/s/' + token + '/download') + '?' + OC.buildQueryString(params); }; + this.fileList.getUploadUrl = function(fileName, dir) { + if (_.isUndefined(dir)) { + dir = this.getCurrentDirectory(); + } + + var pathSections = dir.split('/'); + if (!_.isUndefined(fileName)) { + pathSections.push(fileName); + } + var encodedPath = ''; + _.each(pathSections, function(section) { + if (section !== '') { + encodedPath += '/' + encodeURIComponent(section); + } + }); + var base = ''; + + if (!this._uploader.isXHRUpload()) { + // also add auth in URL due to POST workaround + base = OC.getProtocol() + '://' + token + '@' + OC.getHost() + (OC.getPort() ? ':' + OC.getPort() : ''); + } + return base + OC.getRootPath() + '/public.php/webdav' + encodedPath; + }; + this.fileList.getAjaxUrl = function (action, params) { params = params || {}; params.t = token; @@ -203,20 +228,12 @@ OCA.Sharing.PublicApp = { OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments); }; - var file_upload_start = $('#file_upload_start'); - file_upload_start.on('fileuploadadd', function (e, data) { - var fileDirectory = ''; - if (typeof data.files[0].relativePath !== 'undefined') { - fileDirectory = data.files[0].relativePath; + this.fileList._uploader.on('fileuploadadd', function(e, data) { + if (!data.headers) { + data.headers = {}; } - // Add custom data to the upload handler - data.formData = { - requesttoken: $('#publicUploadRequestToken').val(), - dirToken: $('#dirToken').val(), - subdir: data.targetDir || self.fileList.getCurrentDirectory(), - file_directory: fileDirectory - }; + data.headers.Authorization = 'Basic ' + btoa(token + ':'); }); // do not allow sharing from the public page |