public function uploadAction()
    {
        $request = $this
            ->requestStack
            ->getCurrentRequest();

        /**
         * @var UploadedFile $file
         */
        $file = $request
            ->files
            ->get($this->uploadFieldName);

        if (!($file instanceof UploadedFile)) {
            return new JsonResponse([
                'status' => 'ko',
                'response' => [
                    'message' => 'Image not found',
                ],
            ]);
        }

        try {
            $image = $this
                ->imageUploader
                ->uploadImage($file);

            $routes = $this
                ->router
                ->getRouteCollection();

            $response = [
                'status' => 'ok',
                'response' => [
                    'id' => $image->getId(),
                    'extension' => $image->getExtension(),
                    'routes' => [
                        'view' => $routes
                            ->get($this->viewImageRouteName)
                            ->getPath(),
                        'resize' => $routes
                            ->get($this->resizeImageRouteName)
                            ->getPath(),
                    ],
                ],
            ];
        } catch (Exception $exception) {
            $response = [
                'status' => 'ko',
                'response' => [
                    'message' => $exception->getMessage(),
                ],
            ];
        }

        return new JsonResponse($response);
    }
public function uploadAction()
    {
        $request = $this
            ->requestStack
            ->getCurrentRequest();

        /**
         * @var UploadedFile $file
         */
        $file = $request
            ->files
            ->get($this->uploadFieldName);

        if (!($file instanceof UploadedFile)) {
            return new JsonResponse([
                'status' => 'ko',
                'response' => [
                    'message' => 'Image not found',
                ],
            ]);
        }

        try {
            $image = $this
                ->imageUploader
                ->uploadImage($file);

            $routes = $this
                ->router
                ->getRouteCollection();

            $response = [
                'status' => 'ok',
                'response' => [
                    'id' => $image->getId(),
                    'extension' => $image->getExtension(),
                    'routes' => [
                        'view' => $routes
                            ->get($this->viewImageRouteName)
                            ->getPath(),
                        'resize' => $routes
                            ->get($this->resizeImageRouteName)
                            ->getPath(),
                    ],
                ],
            ];
        } catch (Exception $exception) {
            $response = [
                'status' => 'ko',
                'response' => [
                    'message' => $exception->getMessage(),
                ],
            ];
        }

        return new JsonResponse($response);
    }
public function uploadAction ( ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; /**
         * @var UploadedFile $file
         */ $ file = $ request -> files -> get ( $ this -> uploadFieldName ) ; if ( ! ( $ file instanceof UploadedFile ) ) { return new JsonResponse ( [ 'status' => 'ko' , 'response' => [ 'message' => 'Image not found' , ] , ] ) ; } try { $ image = $ this -> imageUploader -> uploadImage ( $ file ) ; $ routes = $ this -> router -> getRouteCollection ( ) ; $ response = [ 'status' => 'ok' , 'response' => [ 'id' => $ image -> getId ( ) , 'extension' => $ image -> getExtension ( ) , 'routes' => [ 'view' => $ routes -> get ( $ this -> viewImageRouteName ) -> getPath ( ) , 'resize' => $ routes -> get ( $ this -> resizeImageRouteName ) -> getPath ( ) , ] , ] , ] ; } catch ( Exception $ exception ) { $ response = [ 'status' => 'ko' , 'response' => [ 'message' => $ exception -> getMessage ( ) , ] , ] ; } return new JsonResponse ( $ response ) ; }
Dynamic upload action.

@return JsonResponse Upload response
Dynamic upload action .