multipart upload for s3 object storage

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2017-09-18 18:24:53 +02:00
parent d2b8bfc915
commit d3a57a7568
No known key found for this signature in database
GPG Key ID: CBCA68FBAEBF98C9
1 changed files with 22 additions and 5 deletions

View File

@ -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
]);
}
}
}