diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-02-08 14:30:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-08 14:30:02 +0100 |
commit | 26e0c14c6d90adae72797e759024d140047b827c (patch) | |
tree | a5b48a45e95c25cefdd8ab0ded4c24667b926ef1 /lib/private | |
parent | 12c9bad5b26509feee1527596b2e54b86732c788 (diff) | |
parent | 3499cbdb76d264353d3d9f358601694bc4aae956 (diff) | |
download | nextcloud-server-26e0c14c6d90adae72797e759024d140047b827c.tar.gz nextcloud-server-26e0c14c6d90adae72797e759024d140047b827c.zip |
Merge pull request #8033 from nextcloud/s3-uploader
Use S3Client::upload instead of splitting single/multipart upload ourselves
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/ObjectStore/S3ObjectTrait.php | 45 |
1 files changed, 2 insertions, 43 deletions
diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index 9c5cf9ccc6c..defeda4c21a 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -75,51 +75,10 @@ trait S3ObjectTrait { * @since 7.0.0 */ function writeObject($urn, $stream) { - $stat = fstat($stream); - - if ($stat['size'] && $stat['size'] < S3_UPLOAD_PART_SIZE) { - $this->singlePartUpload($urn, $stream); - } else { - $this->multiPartUpload($urn, $stream); - } - - } - - protected function singlePartUpload($urn, $stream) { - $this->getConnection()->putObject([ - 'Bucket' => $this->bucket, - 'Key' => $urn, - 'Body' => $stream - ]); - } - - protected function multiPartUpload($urn, $stream) { - $uploader = new MultipartUploader($this->getConnection(), $stream, [ - 'bucket' => $this->bucket, - 'key' => $urn, + $this->getConnection()->upload($this->bucket, $urn, $stream, 'private', [ + 'mup_threshold' => S3_UPLOAD_PART_SIZE, 'part_size' => S3_UPLOAD_PART_SIZE ]); - - $tries = 0; - - do { - try { - $result = $uploader->upload(); - } catch (MultipartUploadException $e) { - \OC::$server->getLogger()->logException($e); - rewind($stream); - $tries++; - - if ($tries < 5) { - $uploader = new MultipartUploader($this->getConnection(), $stream, [ - 'state' => $e->getState() - ]); - } else { - $this->getConnection()->abortMultipartUpload($e->getState()->getId()); - throw $e; - } - } - } while (!isset($result) && $tries < 5); } /** |