summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/ObjectStore/ObjectStoreStorage.php
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-10-25 17:57:21 +0200
committerMorris Jobke <hey@morrisjobke.de>2017-10-26 16:31:59 +0200
commit405bbc1c6195f7735d920451fe18476ec4bd0054 (patch)
tree31d923ea0b294b73f3f634140013d959b39e5486 /lib/private/Files/ObjectStore/ObjectStoreStorage.php
parent9f5e1648c106893425790385b8741499ae08f2b6 (diff)
downloadnextcloud-server-405bbc1c6195f7735d920451fe18476ec4bd0054.tar.gz
nextcloud-server-405bbc1c6195f7735d920451fe18476ec4bd0054.zip
Improve mimetype detection for object storages
Object storage instances always fall back to the content based mimetype detection, because the file name for object storage was always random due to the fact that it was temporarily storage in a generated temp file. This patch adds a check before that to make sure to use the original file name for this purpose and also remove possible other extensions like the versioning or part file extension. Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private/Files/ObjectStore/ObjectStoreStorage.php')
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreStorage.php10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
index ded69e8079b..15df808684b 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -390,7 +390,15 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
$stat['size'] = filesize($tmpFile);
$stat['mtime'] = $mTime;
$stat['storage_mtime'] = $mTime;
- $stat['mimetype'] = \OC::$server->getMimeTypeDetector()->detect($tmpFile);
+
+ // run path based detection first, to use file extension because $tmpFile is only a random string
+ $mimetypeDetector = \OC::$server->getMimeTypeDetector();
+ $mimetype = $mimetypeDetector->detectPath($path);
+ if ($mimetype === 'application/octet-stream') {
+ $mimetype = $mimetypeDetector->detect($tmpFile);
+ }
+
+ $stat['mimetype'] = $mimetype;
$stat['etag'] = $this->getETag($path);
$fileId = $this->getCache()->put($path, $stat);