public function uploadAction(Request $request)
    {
        $files = $request->files;
        $data = [];

        if ($files->count() === 1) {
            foreach ($files as $file) {
                $data = $this->doRequestUpload($file);
                break;
            }
        } else {
            if ($files->count() === 0) {
                $src = $request->request->get('src');
                $originalName = $request->request->get('originalname');
                if (null !== $src && null !== $originalName) {
                    $data = $this->doUpload($src, $originalName);
                } else {
                    throw new NotFoundHttpException('No file to upload');
                }
            } else {
                throw new BadRequestHttpException('You can upload only one file by request');
            }
        }

        return $this->createJsonResponse($data, 201);
    }
public function uploadAction(Request $request)
    {
        $files = $request->files;
        $data = [];

        if ($files->count() === 1) {
            foreach ($files as $file) {
                $data = $this->doRequestUpload($file);
                break;
            }
        } else {
            if ($files->count() === 0) {
                $src = $request->request->get('src');
                $originalName = $request->request->get('originalname');
                if (null !== $src && null !== $originalName) {
                    $data = $this->doUpload($src, $originalName);
                } else {
                    throw new NotFoundHttpException('No file to upload');
                }
            } else {
                throw new BadRequestHttpException('You can upload only one file by request');
            }
        }

        return $this->createJsonResponse($data, 201);
    }
public function uploadAction ( Request $ request ) { $ files = $ request -> files ; $ data = [ ] ; if ( $ files -> count ( ) === 1 ) { foreach ( $ files as $ file ) { $ data = $ this -> doRequestUpload ( $ file ) ; break ; } } else { if ( $ files -> count ( ) === 0 ) { $ src = $ request -> request -> get ( 'src' ) ; $ originalName = $ request -> request -> get ( 'originalname' ) ; if ( null !== $ src && null !== $ originalName ) { $ data = $ this -> doUpload ( $ src , $ originalName ) ; } else { throw new NotFoundHttpException ( 'No file to upload' ) ; } } else { throw new BadRequestHttpException ( 'You can upload only one file by request' ) ; } } return $ this -> createJsonResponse ( $ data , 201 ) ; }
Upload file action

@return \Symfony\Component\HttpFoundation\JsonResponse
@throws NotFoundHttpException No file in the request
@throws BadRequestHttpException Only on file can be upload
@Rest\Security("is_fully_authenticated() & has_role('ROLE_API_USER')")
Upload file action