Răsfoiți Sursa

Oubli du baseUrl dans images

Sangfroid 1 lună în urmă
părinte
comite
4306def463
1 a modificat fișierele cu 3 adăugiri și 2 ștergeri
  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()]);