diff options
author | Robin Appelman <robin@icewind.nl> | 2017-09-18 18:24:53 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-09-20 17:51:58 +0200 |
commit | e4e5e735db2ae1d73432a3ec1ebf1a6654f2eda8 (patch) | |
tree | 4f97cfa9d1425df06984bd929478f0cb38261a24 | |
parent | e43400eddbfdac765c8dcc5d90b4398e304dbaaf (diff) | |
download | nextcloud-server-e4e5e735db2ae1d73432a3ec1ebf1a6654f2eda8.tar.gz nextcloud-server-e4e5e735db2ae1d73432a3ec1ebf1a6654f2eda8.zip |
multipart upload for s3 object storage
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | lib/private/Files/ObjectStore/S3ObjectTrait.php | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index 3ba4da92b98..f7d9fb305c2 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -21,6 +21,8 @@ namespace OC\Files\ObjectStore; +use Aws\Exception\MultipartUploadException; +use Aws\S3\MultipartUploader; use Aws\S3\S3Client; use Psr\Http\Message\StreamInterface; @@ -60,11 +62,26 @@ trait S3ObjectTrait { * @since 7.0.0 */ function writeObject($urn, $stream) { - $this->getConnection()->putObject([ - 'Bucket' => $this->bucket, - 'Key' => $urn, - 'Body' => $stream + $uploader = new MultipartUploader($this->getConnection(), $stream, [ + 'bucket' => $this->bucket, + 'key' => $urn, ]); + $tries = 0; + do { + try { + $result = $uploader->upload(); + } catch (MultipartUploadException $e) { + rewind($stream); + $tries++; + if ($tries < 5) { + $uploader = new MultipartUploader($this->getConnection(), $stream, [ + 'state' => $e->getState() + ]); + } else { + $this->getConnection()->abortMultipartUpload($e->getState()->getId()); + } + } + } while (!isset($result) && $tries < 5); } /** @@ -79,4 +96,4 @@ trait S3ObjectTrait { 'Key' => $urn ]); } -}
\ No newline at end of file +} |