|
@@ -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()]);
|