@@ -23,10 +23,7 @@ |
||
| 23 | 23 | |
| 24 | 24 | namespace OC\Files\ObjectStore; |
| 25 | 25 | |
| 26 | -use Aws\Exception\MultipartUploadException; |
|
| 27 | -use Aws\S3\MultipartUploader; |
|
| 28 | 26 | use Aws\S3\S3Client; |
| 29 | -use Psr\Http\Message\StreamInterface; |
|
| 30 | 27 | |
| 31 | 28 | const S3_UPLOAD_PART_SIZE = 524288000; // 500MB |
| 32 | 29 | |
@@ -31,66 +31,66 @@ |
||
| 31 | 31 | const S3_UPLOAD_PART_SIZE = 524288000; // 500MB |
| 32 | 32 | |
| 33 | 33 | trait S3ObjectTrait { |
| 34 | - /** |
|
| 35 | - * Returns the connection |
|
| 36 | - * |
|
| 37 | - * @return S3Client connected client |
|
| 38 | - * @throws \Exception if connection could not be made |
|
| 39 | - */ |
|
| 40 | - abstract protected function getConnection(); |
|
| 34 | + /** |
|
| 35 | + * Returns the connection |
|
| 36 | + * |
|
| 37 | + * @return S3Client connected client |
|
| 38 | + * @throws \Exception if connection could not be made |
|
| 39 | + */ |
|
| 40 | + abstract protected function getConnection(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param string $urn the unified resource name used to identify the object |
|
| 44 | - * @return resource stream with the read data |
|
| 45 | - * @throws \Exception when something goes wrong, message will be logged |
|
| 46 | - * @since 7.0.0 |
|
| 47 | - */ |
|
| 48 | - function readObject($urn) { |
|
| 49 | - $client = $this->getConnection(); |
|
| 50 | - $command = $client->getCommand('GetObject', [ |
|
| 51 | - 'Bucket' => $this->bucket, |
|
| 52 | - 'Key' => $urn |
|
| 53 | - ]); |
|
| 54 | - $request = \Aws\serialize($command); |
|
| 55 | - $headers = []; |
|
| 56 | - foreach ($request->getHeaders() as $key => $values) { |
|
| 57 | - foreach ($values as $value) { |
|
| 58 | - $headers[] = "$key: $value"; |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - $opts = [ |
|
| 62 | - 'http' => [ |
|
| 63 | - 'header' => $headers |
|
| 64 | - ] |
|
| 65 | - ]; |
|
| 42 | + /** |
|
| 43 | + * @param string $urn the unified resource name used to identify the object |
|
| 44 | + * @return resource stream with the read data |
|
| 45 | + * @throws \Exception when something goes wrong, message will be logged |
|
| 46 | + * @since 7.0.0 |
|
| 47 | + */ |
|
| 48 | + function readObject($urn) { |
|
| 49 | + $client = $this->getConnection(); |
|
| 50 | + $command = $client->getCommand('GetObject', [ |
|
| 51 | + 'Bucket' => $this->bucket, |
|
| 52 | + 'Key' => $urn |
|
| 53 | + ]); |
|
| 54 | + $request = \Aws\serialize($command); |
|
| 55 | + $headers = []; |
|
| 56 | + foreach ($request->getHeaders() as $key => $values) { |
|
| 57 | + foreach ($values as $value) { |
|
| 58 | + $headers[] = "$key: $value"; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + $opts = [ |
|
| 62 | + 'http' => [ |
|
| 63 | + 'header' => $headers |
|
| 64 | + ] |
|
| 65 | + ]; |
|
| 66 | 66 | |
| 67 | - $context = stream_context_create($opts); |
|
| 68 | - return fopen($request->getUri(), 'r', false, $context); |
|
| 69 | - } |
|
| 67 | + $context = stream_context_create($opts); |
|
| 68 | + return fopen($request->getUri(), 'r', false, $context); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param string $urn the unified resource name used to identify the object |
|
| 73 | - * @param resource $stream stream with the data to write |
|
| 74 | - * @throws \Exception when something goes wrong, message will be logged |
|
| 75 | - * @since 7.0.0 |
|
| 76 | - */ |
|
| 77 | - function writeObject($urn, $stream) { |
|
| 78 | - $this->getConnection()->upload($this->bucket, $urn, $stream, 'private', [ |
|
| 79 | - 'mup_threshold' => S3_UPLOAD_PART_SIZE, |
|
| 80 | - 'part_size' => S3_UPLOAD_PART_SIZE |
|
| 81 | - ]); |
|
| 82 | - } |
|
| 71 | + /** |
|
| 72 | + * @param string $urn the unified resource name used to identify the object |
|
| 73 | + * @param resource $stream stream with the data to write |
|
| 74 | + * @throws \Exception when something goes wrong, message will be logged |
|
| 75 | + * @since 7.0.0 |
|
| 76 | + */ |
|
| 77 | + function writeObject($urn, $stream) { |
|
| 78 | + $this->getConnection()->upload($this->bucket, $urn, $stream, 'private', [ |
|
| 79 | + 'mup_threshold' => S3_UPLOAD_PART_SIZE, |
|
| 80 | + 'part_size' => S3_UPLOAD_PART_SIZE |
|
| 81 | + ]); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @param string $urn the unified resource name used to identify the object |
|
| 86 | - * @return void |
|
| 87 | - * @throws \Exception when something goes wrong, message will be logged |
|
| 88 | - * @since 7.0.0 |
|
| 89 | - */ |
|
| 90 | - function deleteObject($urn) { |
|
| 91 | - $this->getConnection()->deleteObject([ |
|
| 92 | - 'Bucket' => $this->bucket, |
|
| 93 | - 'Key' => $urn |
|
| 94 | - ]); |
|
| 95 | - } |
|
| 84 | + /** |
|
| 85 | + * @param string $urn the unified resource name used to identify the object |
|
| 86 | + * @return void |
|
| 87 | + * @throws \Exception when something goes wrong, message will be logged |
|
| 88 | + * @since 7.0.0 |
|
| 89 | + */ |
|
| 90 | + function deleteObject($urn) { |
|
| 91 | + $this->getConnection()->deleteObject([ |
|
| 92 | + 'Bucket' => $this->bucket, |
|
| 93 | + 'Key' => $urn |
|
| 94 | + ]); |
|
| 95 | + } |
|
| 96 | 96 | } |