multipart upload for s3 object storage
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
e43400eddb
commit
e4e5e735db
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
namespace OC\Files\ObjectStore;
|
namespace OC\Files\ObjectStore;
|
||||||
|
|
||||||
|
use Aws\Exception\MultipartUploadException;
|
||||||
|
use Aws\S3\MultipartUploader;
|
||||||
use Aws\S3\S3Client;
|
use Aws\S3\S3Client;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
|
||||||
|
@ -60,11 +62,26 @@ trait S3ObjectTrait {
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
*/
|
*/
|
||||||
function writeObject($urn, $stream) {
|
function writeObject($urn, $stream) {
|
||||||
$this->getConnection()->putObject([
|
$uploader = new MultipartUploader($this->getConnection(), $stream, [
|
||||||
'Bucket' => $this->bucket,
|
'bucket' => $this->bucket,
|
||||||
'Key' => $urn,
|
'key' => $urn,
|
||||||
'Body' => $stream
|
|
||||||
]);
|
]);
|
||||||
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue