From dbaba974ae242f6e286be19b7f44ac57653ceffb Mon Sep 17 00:00:00 2001 From: KallooaSan Date: Tue, 20 Feb 2018 14:13:28 +0400 Subject: [PATCH] Add extension to file path on api upload for extension-mapping (#2481) --- lib/Alchemy/Phrasea/Controller/Api/V1Controller.php | 12 +++++++++++- lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index a3022272c2..c9e6eeb935 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -17,6 +17,7 @@ use Alchemy\Phrasea\Account\Command\UpdatePasswordCommand; use Alchemy\Phrasea\Account\RestrictedStatusExtractor; use Alchemy\Phrasea\Application\Helper\DataboxLoggerAware; use Alchemy\Phrasea\Application\Helper\DispatcherAware; +use Alchemy\Phrasea\Application\Helper\FilesystemAware; use Alchemy\Phrasea\Application\Helper\JsonBodyAware; use Alchemy\Phrasea\Authentication\Exception\RegistrationException; use Alchemy\Phrasea\Authentication\RegistrationService; @@ -96,10 +97,12 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Translation\TranslatorInterface; + class V1Controller extends Controller { use DataboxLoggerAware; use DispatcherAware; + use FilesystemAware; use JsonBodyAware; const OBJECT_TYPE_USER = 'http://api.phraseanet.com/api/objects/user'; @@ -913,7 +916,14 @@ class V1Controller extends Controller ))->createResponse(); } - $media = $this->app->getMediaFromUri($file->getPathname()); + // Add file extension + $uploadedFilename = $file->getRealPath(); + + $renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); + + $this->getFilesystem()->rename($uploadedFilename, $renamedFilename); + + $media = $this->app->getMediaFromUri($renamedFilename); $Package = new File($this->app, $media, $collection, $file->getClientOriginalName()); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php index 622c429122..fdf999557f 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php @@ -37,6 +37,7 @@ class V1 extends Api implements ControllerProviderInterface, ServiceProviderInte return (new V1Controller($app)) ->setDataboxLoggerLocator($app['phraseanet.logger']) ->setDispatcher($app['dispatcher']) + ->setFileSystemLocator(new LazyLocator($app, 'filesystem')) ->setJsonBodyHelper(new LazyLocator($app, 'json.body_helper')); }); }