ソースを参照

Merge branch 'master' into introblock-extension

Sangfroid 1 ヶ月 前
コミット
269eb67166
1 ファイル変更3 行追加2 行削除
  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()]);