summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/ObjectStore
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/ObjectStore')
-rw-r--r--lib/private/Files/ObjectStore/S3ObjectTrait.php45
1 files changed, 24 insertions, 21 deletions
diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php
index 6188357521b..0939dd2a23c 100644
--- a/lib/private/Files/ObjectStore/S3ObjectTrait.php
+++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php
@@ -30,6 +30,7 @@ use Aws\S3\MultipartUploader;
use Aws\S3\ObjectUploader;
use Aws\S3\S3Client;
use Icewind\Streams\CallbackWrapper;
+use OC\Files\Stream\SeekableHttpStream;
const S3_UPLOAD_PART_SIZE = 524288000; // 500MB
@@ -49,27 +50,29 @@ trait S3ObjectTrait {
* @since 7.0.0
*/
function readObject($urn) {
- $client = $this->getConnection();
- $command = $client->getCommand('GetObject', [
- 'Bucket' => $this->bucket,
- 'Key' => $urn
- ]);
- $request = \Aws\serialize($command);
- $headers = [];
- foreach ($request->getHeaders() as $key => $values) {
- foreach ($values as $value) {
- $headers[] = "$key: $value";
+ return SeekableHttpStream::open(function ($range) use ($urn) {
+ $command = $this->getConnection()->getCommand('GetObject', [
+ 'Bucket' => $this->bucket,
+ 'Key' => $urn,
+ 'Range' => 'bytes=' . $range,
+ ]);
+ $request = \Aws\serialize($command);
+ $headers = [];
+ foreach ($request->getHeaders() as $key => $values) {
+ foreach ($values as $value) {
+ $headers[] = "$key: $value";
+ }
}
- }
- $opts = [
- 'http' => [
- 'protocol_version' => 1.1,
- 'header' => $headers
- ]
- ];
+ $opts = [
+ 'http' => [
+ 'protocol_version' => 1.1,
+ 'header' => $headers,
+ ],
+ ];
- $context = stream_context_create($opts);
- return fopen($request->getUri(), 'r', false, $context);
+ $context = stream_context_create($opts);
+ return fopen($request->getUri(), 'r', false, $context);
+ });
}
/**
@@ -87,7 +90,7 @@ trait S3ObjectTrait {
$uploader = new MultipartUploader($this->getConnection(), $countStream, [
'bucket' => $this->bucket,
'key' => $urn,
- 'part_size' => S3_UPLOAD_PART_SIZE
+ 'part_size' => S3_UPLOAD_PART_SIZE,
]);
try {
@@ -114,7 +117,7 @@ trait S3ObjectTrait {
function deleteObject($urn) {
$this->getConnection()->deleteObject([
'Bucket' => $this->bucket,
- 'Key' => $urn
+ 'Key' => $urn,
]);
}