diff --git a/docker/dev/nginx_proxy.conf b/docker/dev/nginx_proxy.conf new file mode 100644 index 00000000000..d8b6f7c1729 --- /dev/null +++ b/docker/dev/nginx_proxy.conf @@ -0,0 +1,6 @@ +client_max_body_size 100M; + +proxy_connect_timeout 6003; +proxy_send_timeout 3600; +proxy_read_timeout 3600; +send_timeout 3600; diff --git a/docker/php/conf.d/default.ini b/docker/php/conf.d/default.ini index 6ee3dd07d42..e177e7f3ec2 100644 --- a/docker/php/conf.d/default.ini +++ b/docker/php/conf.d/default.ini @@ -6,3 +6,5 @@ apc.enable_cli = On session.use_strict_mode = 1 zend.detect_unicode = 0 intl.default_locale = fr +upload_max_filesize = 15M +post_max_size = 20M diff --git a/src/Controller/Api/FormationUploadFileController.php b/src/Controller/Api/FormationUploadFileController.php index 3c6ab77d464..ef695446d8e 100644 --- a/src/Controller/Api/FormationUploadFileController.php +++ b/src/Controller/Api/FormationUploadFileController.php @@ -4,24 +4,40 @@ use App\Entity\AdherentFormation\Formation; use App\Formation\FormationHandler; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +use Symfony\Component\Validator\Constraints\File; +use Symfony\Component\Validator\Validator\ValidatorInterface; class FormationUploadFileController extends AbstractController { - public function __invoke(Request $request, Formation $formation, FormationHandler $formationHandler): Formation - { + public function __invoke( + EntityManagerInterface $entityManager, + ValidatorInterface $validator, + Request $request, + Formation $formation, + FormationHandler $formationHandler, + ): Response { $uploadedFile = $request->files->get('file'); if (!$uploadedFile) { throw new BadRequestHttpException('Key "file" is required'); } + $errors = $validator->validate($uploadedFile, [new File(maxSize: '10M')]); + + if ($errors->count()) { + return $this->json($errors, 400); + } + $formation->setFile($uploadedFile); $formationHandler->handleFile($formation); + $entityManager->flush(); - return $formation; + return $this->json('OK'); } } diff --git a/src/DataFixtures/ORM/LoadAdherentFormationData.php b/src/DataFixtures/ORM/LoadAdherentFormationData.php index e630083018f..9789cb9946a 100644 --- a/src/DataFixtures/ORM/LoadAdherentFormationData.php +++ b/src/DataFixtures/ORM/LoadAdherentFormationData.php @@ -144,7 +144,7 @@ private function createFile(Formation $formation): void $this->formationHandler->handleFile($formation); } - public function getDependencies() + public function getDependencies(): array { return [ LoadAdminData::class,