diff --git a/apps/workflowengine/js/filemimetypeplugin.js b/apps/workflowengine/js/filemimetypeplugin.js
index 33cbbd7fd7e27428022f02f7cdf5329576bd3437..9fc9e3452f414af6cbefdd042da3a504879b2150 100644
Binary files a/apps/workflowengine/js/filemimetypeplugin.js and b/apps/workflowengine/js/filemimetypeplugin.js differ
diff --git a/apps/workflowengine/lib/Check/FileMimeType.php b/apps/workflowengine/lib/Check/FileMimeType.php
index 1de9a70a17d54db371aa5b1e5dd4758a75f8673b..4a985840e60cb089c67ccea748fc573788c00f0f 100644
--- a/apps/workflowengine/lib/Check/FileMimeType.php
+++ b/apps/workflowengine/lib/Check/FileMimeType.php
@@ -23,12 +23,13 @@ namespace OCA\WorkflowEngine\Check;
 
 
 use OCP\Files\IMimeTypeDetector;
+use OCP\Files\Storage\IStorage;
 use OCP\IL10N;
 use OCP\IRequest;
 
 class FileMimeType extends AbstractStringCheck {
 
-	/** @var string */
+	/** @var array */
 	protected $mimeType;
 
 	/** @var IRequest */
@@ -37,6 +38,12 @@ class FileMimeType extends AbstractStringCheck {
 	/** @var IMimeTypeDetector */
 	protected $mimeTypeDetector;
 
+	/** @var IStorage */
+	protected $storage;
+
+	/** @var string */
+	protected $path;
+
 	/**
 	 * @param IL10N $l
 	 * @param IRequest $request
@@ -48,27 +55,97 @@ class FileMimeType extends AbstractStringCheck {
 		$this->mimeTypeDetector = $mimeTypeDetector;
 	}
 
+	/**
+	 * @param IStorage $storage
+	 * @param string $path
+	 */
+	public function setFileInfo(IStorage $storage, $path) {
+		$this->storage = $storage;
+		$this->path = $path;
+		if (!isset($this->mimeType[$this->storage->getId()][$this->path])
+			|| $this->mimeType[$this->storage->getId()][$this->path] === '') {
+			$this->mimeType[$this->storage->getId()][$this->path] = null;
+		}
+	}
+
 	/**
 	 * @return string
 	 */
 	protected function getActualValue() {
-		if ($this->mimeType !== null) {
-			return $this->mimeType;
+		if ($this->mimeType[$this->storage->getId()][$this->path] !== null) {
+			return $this->mimeType[$this->storage->getId()][$this->path];
 		}
 
-		$this->mimeType = '';
+		$this->mimeType[$this->storage->getId()][$this->path] = '';
 		if ($this->isWebDAVRequest()) {
 			if ($this->request->getMethod() === 'PUT') {
 				$path = $this->request->getPathInfo();
-				$this->mimeType = $this->mimeTypeDetector->detectPath($path);
+				$this->mimeType[$this->storage->getId()][$this->path] = $this->mimeTypeDetector->detectPath($path);
+				return $this->mimeType[$this->storage->getId()][$this->path];
 			}
-		} else if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
+		}
+
+		if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
 			$files = $this->request->getUploadedFile('files');
 			if (isset($files['type'][0])) {
-				$this->mimeType = $files['type'][0];
+				$mimeType = $files['type'][0];
+				if ($this->mimeType === 'application/octet-stream') {
+					// Maybe not...
+					$mimeTypeTest = $this->mimeTypeDetector->detectPath($files['name'][0]);
+					if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
+						$mimeType = $mimeTypeTest;
+					} else {
+						$mimeTypeTest = $this->mimeTypeDetector->detect($files['tmp_name'][0]);
+						if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
+							$mimeType = $mimeTypeTest;
+						}
+					}
+				}
+				$this->mimeType[$this->storage->getId()][$this->path] = $mimeType;
+				return $mimeType;
+			}
+		}
+
+		$this->mimeType[$this->storage->getId()][$this->path] = $this->storage->getMimeType($this->path);
+		if ($this->mimeType[$this->storage->getId()][$this->path] === 'application/octet-stream') {
+			$this->mimeType[$this->storage->getId()][$this->path] = $this->detectMimetypeFromPath();
+		}
+
+		return $this->mimeType[$this->storage->getId()][$this->path];
+	}
+
+	/**
+	 * @return string
+	 */
+	protected function detectMimetypeFromPath() {
+		$mimeType = $this->mimeTypeDetector->detectPath($this->path);
+		if ($mimeType !== 'application/octet-stream' && $mimeType !== false) {
+			return $mimeType;
+		}
+
+		if ($this->storage->instanceOfStorage('\OC\Files\Storage\Local')
+			|| $this->storage->instanceOfStorage('\OC\Files\Storage\Home')
+			|| $this->storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) {
+			$localFile = $this->storage->getLocalFile($this->path);
+			if ($localFile !== false) {
+				$mimeType = $this->mimeTypeDetector->detect($localFile);
+				if ($mimeType !== false) {
+					return $mimeType;
+				}
 			}
+
+			return 'application/octet-stream';
+		} else {
+			$handle = $this->storage->fopen($this->path, 'r');
+			$data = fread($handle, 8024);
+			fclose($handle);
+			$mimeType = $this->mimeTypeDetector->detectString($data);
+			if ($mimeType !== false) {
+				return $mimeType;
+			}
+
+			return 'application/octet-stream';
 		}
-		return $this->mimeType;
 	}
 
 	/**
diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php
index 492025b7bfc30f2268a723e0db0ec8a1338b175e..66ef0dd2aabfab71fbe44c6e7d2a1d367fd50392 100644
--- a/lib/private/Files/Type/Detection.php
+++ b/lib/private/Files/Type/Detection.php
@@ -200,7 +200,7 @@ class Detection implements IMimeTypeDetector {
 			$info = @strtolower(finfo_file($finfo, $path));
 			finfo_close($finfo);
 			if ($info) {
-				$mimeType = substr($info, 0, strpos($info, ';'));
+				$mimeType = strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
 				return empty($mimeType) ? 'application/octet-stream' : $mimeType;
 			}
 
@@ -238,7 +238,8 @@ class Detection implements IMimeTypeDetector {
 	public function detectString($data) {
 		if (function_exists('finfo_open') and function_exists('finfo_file')) {
 			$finfo = finfo_open(FILEINFO_MIME);
-			return finfo_buffer($finfo, $data);
+			$info = finfo_buffer($finfo, $data);
+			return strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
 		} else {
 			$tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
 			$fh = fopen($tmpFile, 'wb');
diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php
index 7b9dc1b3e4d47e6b7aff89ef39ec3903cb886b4b..11267ee2e7dfcef721575f3df6686ff89d0a535f 100644
--- a/tests/lib/Files/Type/DetectionTest.php
+++ b/tests/lib/Files/Type/DetectionTest.php
@@ -81,7 +81,7 @@ class DetectionTest extends \Test\TestCase {
 
 	public function testDetectString() {
 		$result = $this->detection->detectString("/data/data.tar.gz");
-		$expected = 'text/plain; charset=us-ascii';
+		$expected = 'text/plain';
 		$this->assertEquals($expected, $result);
 	}