diff options
author | Joas Schilling <coding@schilljs.com> | 2017-11-01 11:04:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-01 11:04:15 +0100 |
commit | 3e0789aa94702ea2f331b9023da52862915023d6 (patch) | |
tree | c1c3821b2ddce9144f43f5425ea504d7f7a48c21 /lib | |
parent | defc4bf6a844a72068c98b74f355080325e433cb (diff) | |
parent | 405bbc1c6195f7735d920451fe18476ec4bd0054 (diff) | |
download | nextcloud-server-3e0789aa94702ea2f331b9023da52862915023d6.tar.gz nextcloud-server-3e0789aa94702ea2f331b9023da52862915023d6.zip |
Merge pull request #6958 from nextcloud/improved-mimetype-detection-for-object-storage
Improve mimetype detection for object storages
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/ObjectStore/ObjectStoreStorage.php | 10 | ||||
-rw-r--r-- | lib/private/Files/Type/Detection.php | 4 |
2 files changed, 13 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); diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index cd4ddc2f067..928c68251cf 100644 --- a/lib/private/Files/Type/Detection.php +++ b/lib/private/Files/Type/Detection.php @@ -173,6 +173,10 @@ class Detection implements IMimeTypeDetector { // note: leading dot doesn't qualify as extension if (strpos($fileName, '.') > 0) { + + // remove versioning extension: name.v1508946057 and transfer extension: name.ocTransferId2057600214.part + $fileName = preg_replace('!((\.v\d+)|((.ocTransferId\d+)?.part))$!', '', $fileName); + //try to guess the type by the file extension $extension = strtolower(strrchr($fileName, '.')); $extension = substr($extension, 1); //remove leading . |