diff options
author | Robin Appelman <robin@icewind.nl> | 2021-04-15 17:14:57 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-04-21 15:25:58 +0200 |
commit | effb7dc8ba00c683e3b6717eaf1f358ce1c69b87 (patch) | |
tree | 6d9aa4d783242e56f2f971da6d74d05f66894d1e /lib | |
parent | d2ea068552eb144d491b76e0a0ef8266144dcf45 (diff) | |
download | nextcloud-server-effb7dc8ba00c683e3b6717eaf1f358ce1c69b87.tar.gz nextcloud-server-effb7dc8ba00c683e3b6717eaf1f358ce1c69b87.zip |
set mimetype for objects uploaded to object storages
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/ObjectStore/Azure.php | 14 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/ObjectStoreStorage.php | 4 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/S3ObjectTrait.php | 6 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/StorageObjectStore.php | 8 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/Swift.php | 9 | ||||
-rw-r--r-- | lib/public/Files/ObjectStore/IObjectStore.php | 3 |
6 files changed, 20 insertions, 24 deletions
diff --git a/lib/private/Files/ObjectStore/Azure.php b/lib/private/Files/ObjectStore/Azure.php index 2ef13d60c56..9faaf385bd8 100644 --- a/lib/private/Files/ObjectStore/Azure.php +++ b/lib/private/Files/ObjectStore/Azure.php @@ -24,6 +24,7 @@ namespace OC\Files\ObjectStore; use MicrosoftAzure\Storage\Blob\BlobRestProxy; +use MicrosoftAzure\Storage\Blob\Models\CreateBlockBlobOptions; use MicrosoftAzure\Storage\Common\Exceptions\ServiceException; use OCP\Files\ObjectStore\IObjectStore; @@ -100,13 +101,12 @@ class Azure implements IObjectStore { return $blob->getContentStream(); } - /** - * @param string $urn the unified resource name used to identify the object - * @param resource $stream stream with the data to write - * @throws \Exception when something goes wrong, message will be logged - */ - public function writeObject($urn, $stream) { - $this->getBlobClient()->createBlockBlob($this->containerName, $urn, $stream); + public function writeObject($urn, $stream, string $mimetype = null) { + $options = new CreateBlockBlobOptions(); + if ($mimetype) { + $options->setContentType($mimetype); + } + $this->getBlobClient()->createBlockBlob($this->containerName, $urn, $stream, $options); } /** diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 5d2cbe61ab6..598dd4f80ae 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -486,13 +486,13 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common { ]); $size = $writtenSize; }); - $this->objectStore->writeObject($urn, $countStream); + $this->objectStore->writeObject($urn, $countStream, $mimetype); if (is_resource($countStream)) { fclose($countStream); } $stat['size'] = $size; } else { - $this->objectStore->writeObject($urn, $stream); + $this->objectStore->writeObject($urn, $stream, $mimetype); } } catch (\Exception $ex) { if (!$exists) { diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index 4d6ac3608df..250f8fd1edd 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -78,10 +78,11 @@ trait S3ObjectTrait { /** * @param string $urn the unified resource name used to identify the object * @param resource $stream stream with the data to write + * @param string|null $mimetype the mimetype to set for the remove object @since 22.0.0 * @throws \Exception when something goes wrong, message will be logged * @since 7.0.0 */ - public function writeObject($urn, $stream) { + public function writeObject($urn, $stream, string $mimetype = null) { $count = 0; $countStream = CallbackWrapper::wrap($stream, function ($read) use (&$count) { $count += $read; @@ -91,6 +92,9 @@ trait S3ObjectTrait { 'bucket' => $this->bucket, 'key' => $urn, 'part_size' => $this->uploadPartSize, + 'params' => [ + 'ContentType' => $mimetype + ] ]); try { diff --git a/lib/private/Files/ObjectStore/StorageObjectStore.php b/lib/private/Files/ObjectStore/StorageObjectStore.php index 2076bb3f88b..a3fbc3cec74 100644 --- a/lib/private/Files/ObjectStore/StorageObjectStore.php +++ b/lib/private/Files/ObjectStore/StorageObjectStore.php @@ -65,13 +65,7 @@ class StorageObjectStore implements IObjectStore { throw new \Exception(); } - /** - * @param string $urn the unified resource name used to identify the object - * @param resource $stream stream with the data to write - * @throws \Exception when something goes wrong, message will be logged - * @since 7.0.0 - */ - public function writeObject($urn, $stream) { + public function writeObject($urn, $stream, string $mimetype = null) { $handle = $this->storage->fopen($urn, 'w'); if ($handle) { stream_copy_to_stream($stream, $handle); diff --git a/lib/private/Files/ObjectStore/Swift.php b/lib/private/Files/ObjectStore/Swift.php index 1b0888b0700..f9cccd0e205 100644 --- a/lib/private/Files/ObjectStore/Swift.php +++ b/lib/private/Files/ObjectStore/Swift.php @@ -74,12 +74,7 @@ class Swift implements IObjectStore { return $this->params['container']; } - /** - * @param string $urn the unified resource name used to identify the object - * @param resource $stream stream with the data to write - * @throws \Exception from openstack lib when something goes wrong - */ - public function writeObject($urn, $stream) { + public function writeObject($urn, $stream, string $mimetype = null) { $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('swiftwrite'); file_put_contents($tmpFile, $stream); $handle = fopen($tmpFile, 'rb'); @@ -88,12 +83,14 @@ class Swift implements IObjectStore { $this->getContainer()->createObject([ 'name' => $urn, 'stream' => stream_for($handle), + 'contentType' => $mimetype, ]); } else { $this->getContainer()->createLargeObject([ 'name' => $urn, 'stream' => stream_for($handle), 'segmentSize' => SWIFT_SEGMENT_SIZE, + 'contentType' => $mimetype, ]); } } diff --git a/lib/public/Files/ObjectStore/IObjectStore.php b/lib/public/Files/ObjectStore/IObjectStore.php index e9d948682f8..ea97cd7d384 100644 --- a/lib/public/Files/ObjectStore/IObjectStore.php +++ b/lib/public/Files/ObjectStore/IObjectStore.php @@ -52,10 +52,11 @@ interface IObjectStore { /** * @param string $urn the unified resource name used to identify the object * @param resource $stream stream with the data to write + * @param string|null $mimetype the mimetype to set for the remove object @since 22.0.0 * @throws \Exception when something goes wrong, message will be logged * @since 7.0.0 */ - public function writeObject($urn, $stream); + public function writeObject($urn, $stream, string $mimetype = null); /** * @param string $urn the unified resource name used to identify the object |