From: Erik Moeller Date: Sun, 8 Apr 2012 11:27:32 +0000 (-0700) Subject: Fix for chunked uploading support in API. X-Git-Tag: 1.31.0-rc.0~23967^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=631519fde77e1c630c785d4b89d36986857d12e2;p=lhc%2Fweb%2Fwiklou.git Fix for chunked uploading support in API. Chunked uploading is currently only implemented by Upload Wizard, but is supported in MediaWiki core. It's enabled in Upload Wizard by setting $wgUploadWizardConfig['enableChunked'] to true. When enabled, large files will be split into smaller chunks, by default of 1 MB. This is done through a series of API POST requests. The file is identified by means of a 'filekey' to allow for continuation of uploads from previous offsets. Previously broken behavior: Files were concatenated correctly, but instead of the whole file, one of the chunks was uploaded to the wiki. This was due to the API using the filekey of the chunk, as opposed to the filekey of the whole file. In addition, this change also cleans out the stash information for both filekeys after the upload is complete. [Patch set 2: Whitespace fix] [Patch set 3: Move filekey result past status check] Change-Id: Idac94e953676787f9516051e47c006525f198fd4 --- diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 67165b9a6d..5040c70dcd 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -187,15 +187,28 @@ class ApiUpload extends ApiBase { $this->dieUsage( $status->getWikiText(), 'stashfailed' ); return ; } - $result['filekey'] = $this->mParams['filekey']; + // Check we added the last chunk: if( $this->mParams['offset'] + $chunkSize == $this->mParams['filesize'] ) { $status = $this->mUpload->concatenateChunks(); + if ( !$status->isGood() ) { $this->dieUsage( $status->getWikiText(), 'stashfailed' ); return ; } + + // We have a new filekey for the fully concatenated file. + $result['filekey'] = $this->mUpload->getLocalFile()->getFileKey(); + + // Remove chunk from stash. (Checks against user ownership of chunks.) + $this->mUpload->stash->removeFile( $this->mParams['filekey'] ); + $result['result'] = 'Success'; + + } else { + + // Continue passing through the filekey for adding further chunks. + $result['filekey'] = $this->mParams['filekey']; } } $result['offset'] = $this->mParams['offset'] + $chunkSize;