Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP] increase max uploaded file size #10964

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docker/dev/nginx_proxy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
client_max_body_size 100M;

proxy_connect_timeout 6003;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
send_timeout 3600;
2 changes: 2 additions & 0 deletions docker/php/conf.d/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 19 additions & 3 deletions src/Controller/Api/FormationUploadFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
2 changes: 1 addition & 1 deletion src/DataFixtures/ORM/LoadAdherentFormationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private function createFile(Formation $formation): void
$this->formationHandler->handleFile($formation);
}

public function getDependencies()
public function getDependencies(): array
{
return [
LoadAdminData::class,
Expand Down