src/Api/Controller/CdnObject.php
public function postCreate()
    {
        //  @todo (Pablo - 2017-12-18) - this should be protected using admin permissions or the token uploader
        $oHttpCodes = Factory::service('HttpCodes');
        $oInput     = Factory::service('Input');
        $oCdn       = Factory::service('Cdn', 'nails/module-cdn');
        $aOut       = [];

        // --------------------------------------------------------------------------

        $sBucket = $oInput->post('bucket') ?: $oInput->header('X-Cdn-Bucket');

        if (!$sBucket) {
            throw new ApiException(
                'Bucket not defined',
                $oHttpCodes::STATUS_BAD_REQUEST
            );
        }

        // --------------------------------------------------------------------------

        //  Attempt upload
        $oObject = $oCdn->objectCreate('upload', $sBucket);

        if (!$oObject) {
            throw new ApiException(
                $oCdn->lastError(),
                $oHttpCodes::STATUS_BAD_REQUEST
            );
        }

        //  @todo (Pablo - 2018-06-25) - Reduce the namespace here (i.e remove `object`)
        return Factory::factory('ApiResponse', 'nails/module-api')
            ->setData([
                'object' => $this->formatObject(
                    $oObject,
                    $this->getRequestedUrls()
                ),
            ]);
    }
public function postCreate()
    {
        //  @todo (Pablo - 2017-12-18) - this should be protected using admin permissions or the token uploader
        $oHttpCodes = Factory::service('HttpCodes');
        $oInput     = Factory::service('Input');
        $oCdn       = Factory::service('Cdn', 'nails/module-cdn');
        $aOut       = [];

        // --------------------------------------------------------------------------

        $sBucket = $oInput->post('bucket') ?: $oInput->header('X-Cdn-Bucket');

        if (!$sBucket) {
            throw new ApiException(
                'Bucket not defined',
                $oHttpCodes::STATUS_BAD_REQUEST
            );
        }

        // --------------------------------------------------------------------------

        //  Attempt upload
        $oObject = $oCdn->objectCreate('upload', $sBucket);

        if (!$oObject) {
            throw new ApiException(
                $oCdn->lastError(),
                $oHttpCodes::STATUS_BAD_REQUEST
            );
        }

        //  @todo (Pablo - 2018-06-25) - Reduce the namespace here (i.e remove `object`)
        return Factory::factory('ApiResponse', 'nails/module-api')
            ->setData([
                'object' => $this->formatObject(
                    $oObject,
                    $this->getRequestedUrls()
                ),
            ]);
    }
public function postCreate ( ) { //  @todo (Pablo - 2017-12-18) - this should be protected using admin permissions or the token uploader $ oHttpCodes = Factory :: service ( 'HttpCodes' ) ; $ oInput = Factory :: service ( 'Input' ) ; $ oCdn = Factory :: service ( 'Cdn' , 'nails/module-cdn' ) ; $ aOut = [ ] ; // -------------------------------------------------------------------------- $ sBucket = $ oInput -> post ( 'bucket' ) ? : $ oInput -> header ( 'X-Cdn-Bucket' ) ; if ( ! $ sBucket ) { throw new ApiException ( 'Bucket not defined' , $ oHttpCodes :: STATUS_BAD_REQUEST ) ; } // -------------------------------------------------------------------------- //  Attempt upload $ oObject = $ oCdn -> objectCreate ( 'upload' , $ sBucket ) ; if ( ! $ oObject ) { throw new ApiException ( $ oCdn -> lastError ( ) , $ oHttpCodes :: STATUS_BAD_REQUEST ) ; } //  @todo (Pablo - 2018-06-25) - Reduce the namespace here (i.e remove `object`) return Factory :: factory ( 'ApiResponse' , 'nails/module-api' ) -> setData ( [ 'object' => $ this -> formatObject ( $ oObject , $ this -> getRequestedUrls ( ) ) , ] ) ; }
Upload a new object to the CDN

@return array
Upload a new object to the CDN