Procházet zdrojové kódy

Oubli du baseUrl dans images

Sangfroid před 1 měsícem
rodič
revize
4306def463
1 změnil soubory, kde provedl 3 přidání a 2 odebrání
  1. 3 2
      src/Controller/ImageUploadController.php

+ 3 - 2
src/Controller/ImageUploadController.php

@@ -2,6 +2,7 @@
 
 namespace App\Controller;
 
+use App\Service\BaseUrl;
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\JsonResponse;
@@ -14,7 +15,7 @@ class ImageUploadController extends AbstractController
 {
     #[Route('/upload-image', name: 'upload_image', methods: ['POST'])]
     #[IsGranted('ROLE_AUTHOR')]
-    public function upload(Request $request, SluggerInterface $slugger): JsonResponse
+    public function upload(Request $request, SluggerInterface $slugger, BaseUrl $baseUrl): JsonResponse
     {
         $image = $request->files->get('image');
 
@@ -25,7 +26,7 @@ class ImageUploadController extends AbstractController
 
             try {
                 $image->move($this->getParameter('images_directory'), $newFilename);
-                $url = '/uploads/images/' . $newFilename;
+                $url = $baseUrl->getBasePath() . '/uploads/images/' . $newFilename;
                 return new JsonResponse(['data' => ['filePath' => $url]], JsonResponse::HTTP_OK);
             } catch (FileException $e) {
                 return new JsonResponse(['error' => $e->getCode()]);