@@ -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 +
0 commit comments