main/core/Controller/FileController.php
public function uploadTinyMceAction(Request $request, User $user)
    {
        // grab and validate user submission
        $content = $this->decodeRequest($request);
        if (empty($content) || empty($content['file']) || empty($content['parent'])) {
            $errors = [];
            if (empty($content['parent'])) {
                $errors[] = [
                    'path' => 'parent',
                    'message' => 'This value should not be blank.',
                ];
            }

            if (empty($content['file'])) {
                $errors[] = [
                    'path' => 'file',
                    'message' => 'This value should not be blank.',
                ];
            }

            throw new InvalidDataException('Invalid data.', $errors);
        }

        // check user rights
        $parent = $this->om->getRepository(ResourceNode::class)->findOneBy(['uuid' => $content['parent']]);
        $this->checkPermission('CREATE', new ResourceCollection([$parent], ['type' => 'file']));

        // create the new file resource
        $file = new File();
        $file->setSize($content['file']['size']);
        $file->setName($content['file']['filename']);
        $file->setHashName($content['file']['url']);
        $file->setMimeType($content['file']['mimeType']);

        $rights = [];
        if (!$parent->getWorkspace()) {
            $rights = [
                'ROLE_ANONYMOUS' => [
                    'open' => true, 'export' => true, 'create' => [],
                    'role' => $this->roleManager->getRoleByName('ROLE_ANONYMOUS'),
                ],
            ];
        }

        $file = $this->resourceManager->create(
            $file,
            $this->resourceManager->getResourceTypeByName('file'),
            $user,
            $parent->getWorkspace(),
            $parent,
            null,
            $rights,
            true
        );

        return new JsonResponse($this->serializer->serialize($file->getResourceNode(), [Options::SERIALIZE_MINIMAL]), 201);
    }
public function uploadTinyMceAction(Request $request, User $user)
    {
        // grab and validate user submission
        $content = $this->decodeRequest($request);
        if (empty($content) || empty($content['file']) || empty($content['parent'])) {
            $errors = [];
            if (empty($content['parent'])) {
                $errors[] = [
                    'path' => 'parent',
                    'message' => 'This value should not be blank.',
                ];
            }

            if (empty($content['file'])) {
                $errors[] = [
                    'path' => 'file',
                    'message' => 'This value should not be blank.',
                ];
            }

            throw new InvalidDataException('Invalid data.', $errors);
        }

        // check user rights
        $parent = $this->om->getRepository(ResourceNode::class)->findOneBy(['uuid' => $content['parent']]);
        $this->checkPermission('CREATE', new ResourceCollection([$parent], ['type' => 'file']));

        // create the new file resource
        $file = new File();
        $file->setSize($content['file']['size']);
        $file->setName($content['file']['filename']);
        $file->setHashName($content['file']['url']);
        $file->setMimeType($content['file']['mimeType']);

        $rights = [];
        if (!$parent->getWorkspace()) {
            $rights = [
                'ROLE_ANONYMOUS' => [
                    'open' => true, 'export' => true, 'create' => [],
                    'role' => $this->roleManager->getRoleByName('ROLE_ANONYMOUS'),
                ],
            ];
        }

        $file = $this->resourceManager->create(
            $file,
            $this->resourceManager->getResourceTypeByName('file'),
            $user,
            $parent->getWorkspace(),
            $parent,
            null,
            $rights,
            true
        );

        return new JsonResponse($this->serializer->serialize($file->getResourceNode(), [Options::SERIALIZE_MINIMAL]), 201);
    }
public function uploadTinyMceAction ( Request $ request , User $ user ) { // grab and validate user submission $ content = $ this -> decodeRequest ( $ request ) ; if ( empty ( $ content ) || empty ( $ content [ 'file' ] ) || empty ( $ content [ 'parent' ] ) ) { $ errors = [ ] ; if ( empty ( $ content [ 'parent' ] ) ) { $ errors [ ] = [ 'path' => 'parent' , 'message' => 'This value should not be blank.' , ] ; } if ( empty ( $ content [ 'file' ] ) ) { $ errors [ ] = [ 'path' => 'file' , 'message' => 'This value should not be blank.' , ] ; } throw new InvalidDataException ( 'Invalid data.' , $ errors ) ; } // check user rights $ parent = $ this -> om -> getRepository ( ResourceNode :: class ) -> findOneBy ( [ 'uuid' => $ content [ 'parent' ] ] ) ; $ this -> checkPermission ( 'CREATE' , new ResourceCollection ( [ $ parent ] , [ 'type' => 'file' ] ) ) ; // create the new file resource $ file = new File ( ) ; $ file -> setSize ( $ content [ 'file' ] [ 'size' ] ) ; $ file -> setName ( $ content [ 'file' ] [ 'filename' ] ) ; $ file -> setHashName ( $ content [ 'file' ] [ 'url' ] ) ; $ file -> setMimeType ( $ content [ 'file' ] [ 'mimeType' ] ) ; $ rights = [ ] ; if ( ! $ parent -> getWorkspace ( ) ) { $ rights = [ 'ROLE_ANONYMOUS' => [ 'open' => true , 'export' => true , 'create' => [ ] , 'role' => $ this -> roleManager -> getRoleByName ( 'ROLE_ANONYMOUS' ) , ] , ] ; } $ file = $ this -> resourceManager -> create ( $ file , $ this -> resourceManager -> getResourceTypeByName ( 'file' ) , $ user , $ parent -> getWorkspace ( ) , $ parent , null , $ rights , true ) ; return new JsonResponse ( $ this -> serializer -> serialize ( $ file -> getResourceNode ( ) , [ Options :: SERIALIZE_MINIMAL ] ) , 201 ) ; }
Creates a resource from uploaded file.

@EXT\Route("/tinymce/upload", name="claro_tinymce_file_upload")
@EXT\ParamConverter("user", options={"authenticatedUser" = true})
@EXT\Method("POST")

@param Request $request
@param User    $user

@throws \Exception

@return Response
Creates a resource from uploaded file .