From 030cba1cb4bb8f82818720f9d84b3d812146bdc4 Mon Sep 17 00:00:00 2001 From: Jerome_maarch Date: Mon, 6 Jul 2020 12:13:37 +0200 Subject: [PATCH] fix/14351 : remove string cast for resource on format detection --- src/bundle/digitalResource/Controller/format.php | 13 ++++++++++--- src/bundle/digitalResource/formatInterface.php | 3 +-- .../view/digitalResource/format/index.html | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/bundle/digitalResource/Controller/format.php b/src/bundle/digitalResource/Controller/format.php index bce57b1b0..576051406 100755 --- a/src/bundle/digitalResource/Controller/format.php +++ b/src/bundle/digitalResource/Controller/format.php @@ -183,13 +183,20 @@ class format /** * Get all information about the content file (puid, md5/sha256/sha512 hash) - * @param string $contents The content file * * @return digitalResource/fileInformation The file information object */ - public function getFileInformation($contents) + public function getFileInformation($contents, $extension) { - $contents = base64_decode($contents); + if (is_resource($contents)) { + $contents = base64_decode(stream_get_contents($contents)); + } elseif (filter_var($contents, FILTER_VALIDATE_URL)) { + $contents = stream_get_contents($contents); + } elseif (preg_match('%^[a-zA-Z0-9\\\\/+]*={0,2}$%', $contents)) { + $contents = base64_decode($contents); + } elseif (is_file($contents)) { + $contents = file_get_contents($contents); + } $filename = tempnam(sys_get_temp_dir(), 'digitalResource.format.'); file_put_contents($filename, $contents); diff --git a/src/bundle/digitalResource/formatInterface.php b/src/bundle/digitalResource/formatInterface.php index 272c39490..ac3f9a055 100755 --- a/src/bundle/digitalResource/formatInterface.php +++ b/src/bundle/digitalResource/formatInterface.php @@ -48,8 +48,7 @@ interface formatInterface /** * Get the list of type - * @param string $contents - * @param string $extension + * * @action digitalResource/format/getFileInformation */ public function createFileformatinformation($contents, $extension); diff --git a/src/presentation/maarchRM/Resources/view/digitalResource/format/index.html b/src/presentation/maarchRM/Resources/view/digitalResource/format/index.html index a337b5a75..ce8cac211 100755 --- a/src/presentation/maarchRM/Resources/view/digitalResource/format/index.html +++ b/src/presentation/maarchRM/Resources/view/digitalResource/format/index.html @@ -246,7 +246,7 @@ file that was distributed with this source code. contents : file.contents, extension : file.extension },*/ - data : JSON.stringify({contents : file.contents, extension : file.extension}), + data : JSON.stringify({'contents' : file.contents, 'extension' : file.extension}), contentType : 'application/json', dataType : 'json', success : function (response) { -- GitLab