public function postAction(Request $request)
    {
        $contentUid = $request->request->get('content_uid');
        $contentType = $request->request->get('content_type', null);
        $mediaFolderUid = $request->request->get('folder_uid', null);
        $mediaTitle = $request->request->get('title', 'Untitled media');

        if (null === $mediaFolderUid) {
            $mediaFolder = $this->getMediaFolderRepository()->getRoot();
        } else {
            $mediaFolder = $this->getMediaFolderRepository()->find($mediaFolderUid);
        }

        if (null === $mediaFolder) {
            throw new NotFoundHttpException('Cannot find a media folder');
        }

        if (null !== $content = $this->getClassContentManager()->findOneByTypeAndUid($contentType, $contentUid)) {
            $this->autoCommitContent($content);
        }

        $media = new Media();
        $media->setContent($content);
        $media->setTitle($mediaTitle);
        $media->setMediaFolder($mediaFolder);

        $this->getEntityManager()->persist($media);
        $this->getEntityManager()->flush();

        return $this->createJsonResponse(null, 201, [
            'BB-RESOURCE-UID' => $media->getId(),
            'Location'        => $this->getApplication()->getRouting()->getUrlByRouteName(
                'bb.rest.media.get',
                [
                    'version' => $request->attributes->get('version'),
                    'uid'     => $media->getId(),
                ],
                '',
                false
            ),
        ]);
    }
public function postAction(Request $request)
    {
        $contentUid = $request->request->get('content_uid');
        $contentType = $request->request->get('content_type', null);
        $mediaFolderUid = $request->request->get('folder_uid', null);
        $mediaTitle = $request->request->get('title', 'Untitled media');

        if (null === $mediaFolderUid) {
            $mediaFolder = $this->getMediaFolderRepository()->getRoot();
        } else {
            $mediaFolder = $this->getMediaFolderRepository()->find($mediaFolderUid);
        }

        if (null === $mediaFolder) {
            throw new NotFoundHttpException('Cannot find a media folder');
        }

        if (null !== $content = $this->getClassContentManager()->findOneByTypeAndUid($contentType, $contentUid)) {
            $this->autoCommitContent($content);
        }

        $media = new Media();
        $media->setContent($content);
        $media->setTitle($mediaTitle);
        $media->setMediaFolder($mediaFolder);

        $this->getEntityManager()->persist($media);
        $this->getEntityManager()->flush();

        return $this->createJsonResponse(null, 201, [
            'BB-RESOURCE-UID' => $media->getId(),
            'Location'        => $this->getApplication()->getRouting()->getUrlByRouteName(
                'bb.rest.media.get',
                [
                    'version' => $request->attributes->get('version'),
                    'uid'     => $media->getId(),
                ],
                '',
                false
            ),
        ]);
    }
public function postAction ( Request $ request ) { $ contentUid = $ request -> request -> get ( 'content_uid' ) ; $ contentType = $ request -> request -> get ( 'content_type' , null ) ; $ mediaFolderUid = $ request -> request -> get ( 'folder_uid' , null ) ; $ mediaTitle = $ request -> request -> get ( 'title' , 'Untitled media' ) ; if ( null === $ mediaFolderUid ) { $ mediaFolder = $ this -> getMediaFolderRepository ( ) -> getRoot ( ) ; } else { $ mediaFolder = $ this -> getMediaFolderRepository ( ) -> find ( $ mediaFolderUid ) ; } if ( null === $ mediaFolder ) { throw new NotFoundHttpException ( 'Cannot find a media folder' ) ; } if ( null !== $ content = $ this -> getClassContentManager ( ) -> findOneByTypeAndUid ( $ contentType , $ contentUid ) ) { $ this -> autoCommitContent ( $ content ) ; } $ media = new Media ( ) ; $ media -> setContent ( $ content ) ; $ media -> setTitle ( $ mediaTitle ) ; $ media -> setMediaFolder ( $ mediaFolder ) ; $ this -> getEntityManager ( ) -> persist ( $ media ) ; $ this -> getEntityManager ( ) -> flush ( ) ; return $ this -> createJsonResponse ( null , 201 , [ 'BB-RESOURCE-UID' => $ media -> getId ( ) , 'Location' => $ this -> getApplication ( ) -> getRouting ( ) -> getUrlByRouteName ( 'bb.rest.media.get' , [ 'version' => $ request -> attributes -> get ( 'version' ) , 'uid' => $ media -> getId ( ) , ] , '' , false ) , ] ) ; }
Post a new media.

@param  Request $request
@return Response
@throws BadRequestHttpException
Post a new media .