diff options
author | Robin Appelman <robin@icewind.nl> | 2018-01-24 17:22:05 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-01-29 16:11:23 +0100 |
commit | 8d5b86c159e8845d19f38036cd4a065bf48b4796 (patch) | |
tree | d1172174698ee0b6305a958f5236468a5a0fb794 /lib | |
parent | 9eddb015c17f3a6f5017ca809acf96c6f56808fc (diff) | |
download | nextcloud-server-8d5b86c159e8845d19f38036cd4a065bf48b4796.tar.gz nextcloud-server-8d5b86c159e8845d19f38036cd4a065bf48b4796.zip |
Use S3Client::upload instead of splitting single/multipart upload ourselves
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-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 63eb562fb16..984b5fd1f91 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -73,51 +73,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); } /** |