src/Entity/XiboLibrary.php
public function create($name, $fileLocation, $oldMediaId = null, $updateInLayouts = null, $deleteOldRevisions = null)
    {
    	$this->getLogger()->debug('Preparing media payload ');
            $payload = [
            [
                'name' => 'name',
                'contents' => $name
            ],
            [
                'name' => 'files',
                'contents' => fopen($fileLocation, 'r')
            ]
        ];
        $this->getLogger()->info('Uploading new media file ' . $name);
        if ($oldMediaId != null) {
        	$this->getLogger()->debug('Replacing old media ID ' .$oldMediaId);
            $payload[] = [
                'name' => 'oldMediaId',
                'contents' => $oldMediaId
            ];
            $this->getLogger()->debug('Updating Media in all layouts it is assigned to');
            $payload[] = [
                'name' => 'updateInLayouts',
                'contents' => $updateInLayouts
            ];
            $this->getLogger()->debug('Deleting Old Revisions');
            $payload[] = [
                'name' => 'deleteOldRevisions',
                'contents' => $deleteOldRevisions
            ];
    	}
            $response = $this->doPost('/library', ['multipart' => $payload]);

        if (isset($response['files'][0]['mediaId']))
            $this->getLogger()->debug('Uploaded media ' . $response['files'][0]['name'] . ' Media ID ' . $response['files'][0]['mediaId'] . ' Stored as ' . $response['files'][0]['storedas']);
        	// Response will have the format:
        	/*{
            	"files":[{
                	"name": "Name",
                	"size": 52770969,
                	"type": "video/mp4",
                	"mediaId": 2344,
                	"storedas": "2344.mp4",
                	"error": ""
            	}]
        	}*/
        if (!isset($response['files']) || count($response['files']) != 1)
            throw new XiboApiException('Invalid return from library add');
        if (!empty($response['files'][0]['error']))
            throw new XiboApiException($response['files'][0]['error']);
        // Modify some of the return
        unset($response['files'][0]['url']);
        $response['files'][0]['storedAs'] = $response['files'][0]['storedas'];
        $media = new XiboLibrary($this->getEntityProvider());
        return $media->hydrate($response['files'][0]);

    }
public function create($name, $fileLocation, $oldMediaId = null, $updateInLayouts = null, $deleteOldRevisions = null)
    {
    	$this->getLogger()->debug('Preparing media payload ');
            $payload = [
            [
                'name' => 'name',
                'contents' => $name
            ],
            [
                'name' => 'files',
                'contents' => fopen($fileLocation, 'r')
            ]
        ];
        $this->getLogger()->info('Uploading new media file ' . $name);
        if ($oldMediaId != null) {
        	$this->getLogger()->debug('Replacing old media ID ' .$oldMediaId);
            $payload[] = [
                'name' => 'oldMediaId',
                'contents' => $oldMediaId
            ];
            $this->getLogger()->debug('Updating Media in all layouts it is assigned to');
            $payload[] = [
                'name' => 'updateInLayouts',
                'contents' => $updateInLayouts
            ];
            $this->getLogger()->debug('Deleting Old Revisions');
            $payload[] = [
                'name' => 'deleteOldRevisions',
                'contents' => $deleteOldRevisions
            ];
    	}
            $response = $this->doPost('/library', ['multipart' => $payload]);

        if (isset($response['files'][0]['mediaId']))
            $this->getLogger()->debug('Uploaded media ' . $response['files'][0]['name'] . ' Media ID ' . $response['files'][0]['mediaId'] . ' Stored as ' . $response['files'][0]['storedas']);
        	// Response will have the format:
        	/*{
            	"files":[{
                	"name": "Name",
                	"size": 52770969,
                	"type": "video/mp4",
                	"mediaId": 2344,
                	"storedas": "2344.mp4",
                	"error": ""
            	}]
        	}*/
        if (!isset($response['files']) || count($response['files']) != 1)
            throw new XiboApiException('Invalid return from library add');
        if (!empty($response['files'][0]['error']))
            throw new XiboApiException($response['files'][0]['error']);
        // Modify some of the return
        unset($response['files'][0]['url']);
        $response['files'][0]['storedAs'] = $response['files'][0]['storedas'];
        $media = new XiboLibrary($this->getEntityProvider());
        return $media->hydrate($response['files'][0]);

    }
public function create ( $ name , $ fileLocation , $ oldMediaId = null , $ updateInLayouts = null , $ deleteOldRevisions = null ) { $ this -> getLogger ( ) -> debug ( 'Preparing media payload ' ) ; $ payload = [ [ 'name' => 'name' , 'contents' => $ name ] , [ 'name' => 'files' , 'contents' => fopen ( $ fileLocation , 'r' ) ] ] ; $ this -> getLogger ( ) -> info ( 'Uploading new media file ' . $ name ) ; if ( $ oldMediaId != null ) { $ this -> getLogger ( ) -> debug ( 'Replacing old media ID ' . $ oldMediaId ) ; $ payload [ ] = [ 'name' => 'oldMediaId' , 'contents' => $ oldMediaId ] ; $ this -> getLogger ( ) -> debug ( 'Updating Media in all layouts it is assigned to' ) ; $ payload [ ] = [ 'name' => 'updateInLayouts' , 'contents' => $ updateInLayouts ] ; $ this -> getLogger ( ) -> debug ( 'Deleting Old Revisions' ) ; $ payload [ ] = [ 'name' => 'deleteOldRevisions' , 'contents' => $ deleteOldRevisions ] ; } $ response = $ this -> doPost ( '/library' , [ 'multipart' => $ payload ] ) ; if ( isset ( $ response [ 'files' ] [ 0 ] [ 'mediaId' ] ) ) $ this -> getLogger ( ) -> debug ( 'Uploaded media ' . $ response [ 'files' ] [ 0 ] [ 'name' ] . ' Media ID ' . $ response [ 'files' ] [ 0 ] [ 'mediaId' ] . ' Stored as ' . $ response [ 'files' ] [ 0 ] [ 'storedas' ] ) ; // Response will have the format: /*{
            	"files":[{
                	"name": "Name",
                	"size": 52770969,
                	"type": "video/mp4",
                	"mediaId": 2344,
                	"storedas": "2344.mp4",
                	"error": ""
            	}]
        	}*/ if ( ! isset ( $ response [ 'files' ] ) || count ( $ response [ 'files' ] ) != 1 ) throw new XiboApiException ( 'Invalid return from library add' ) ; if ( ! empty ( $ response [ 'files' ] [ 0 ] [ 'error' ] ) ) throw new XiboApiException ( $ response [ 'files' ] [ 0 ] [ 'error' ] ) ; // Modify some of the return unset ( $ response [ 'files' ] [ 0 ] [ 'url' ] ) ; $ response [ 'files' ] [ 0 ] [ 'storedAs' ] = $ response [ 'files' ] [ 0 ] [ 'storedas' ] ; $ media = new XiboLibrary ( $ this -> getEntityProvider ( ) ) ; return $ media -> hydrate ( $ response [ 'files' ] [ 0 ] ) ; }
Upload new media.
Upload new media file to the CMS library.

@param string $name optional media name
@param string $fileLocation location of the file
@param int $oldMediaId Id of an existing media file which should be replaced with the new upload
@param int $updateInLayouts Flag  set to 1 to update this media in all layouts (use with oldMediaId)
@param int $deleteOldRevisions Flag to either remove or leave the old file revisions (use with oldMediaId)
@return XiboLibrary
@throws XiboApiException
Upload new media . Upload new media file to the CMS library .