src/Bynder/Api/Impl/Upload/FileUploader.php
public function uploadFile($data)
    {
        $uploadedFilePromise = $this->getClosestUploadEndpoint()
            ->then(
                function () use ($data) {
                    return $this->requestUploadInformationAsync($data['filePath']);
                })
            ->then(
                function ($uploadRequestInfo) use ($data) {
                    if ($file = fopen($data['filePath'], 'rb')) {

                        $fileSize = filesize($data['filePath']);

                        $numberOfChunks = round(($fileSize + self::CHUNK_SIZE - 1) / self::CHUNK_SIZE);
                        $chunkNumber = 0;

                        // This is where the magic happens. We create all the promises via an Iterator function.
                        $promises = $this->uploadChunkIterator($file, $data['filePath'], $uploadRequestInfo,
                            $numberOfChunks, $chunkNumber);
                        // After that we batch them all together using each_limit_all, which will guarantee all chunks have been uploaded properly.
                        $eachPromises = Promise\each_limit_all($promises, self::MAX_CONCURRENT_CHUNKS);
                        return $eachPromises->then(
                            function ($value) use ($uploadRequestInfo, $chunkNumber) {
                                return ['requestInfo' => $uploadRequestInfo, 'chunkNumber' => $chunkNumber];
                            });
                    } else {
                        throw new Exception("File not Found");
                    }
                }
            )
            ->then(
                function ($value) {
                    return $this->finalizeUploadAsync($value['requestInfo'], $value['chunkNumber']);
                }
            )
            ->then(
                function ($finalizeResponse) {
                    return $this->hasFinishedSuccessfullyAsync($finalizeResponse)
                        ->then(
                            function ($response) use ($finalizeResponse) {
                                return [
                                    'pollStatus' => $response,
                                    'finalizeData' => $finalizeResponse
                                ];
                            });
                }
            )
            ->then(
                function ($value) use ($data) {
                    if ($value['pollStatus'] != false) {
                        $data['importId'] = $value['finalizeData']['importId'];
                        return $this->saveMediaAsync($data);
                    } else {
                        throw new Exception("Converter did not finish. Upload failed.");
                    }
                }
            );

        return $uploadedFilePromise;
    }
public function uploadFile($data)
    {
        $uploadedFilePromise = $this->getClosestUploadEndpoint()
            ->then(
                function () use ($data) {
                    return $this->requestUploadInformationAsync($data['filePath']);
                })
            ->then(
                function ($uploadRequestInfo) use ($data) {
                    if ($file = fopen($data['filePath'], 'rb')) {

                        $fileSize = filesize($data['filePath']);

                        $numberOfChunks = round(($fileSize + self::CHUNK_SIZE - 1) / self::CHUNK_SIZE);
                        $chunkNumber = 0;

                        // This is where the magic happens. We create all the promises via an Iterator function.
                        $promises = $this->uploadChunkIterator($file, $data['filePath'], $uploadRequestInfo,
                            $numberOfChunks, $chunkNumber);
                        // After that we batch them all together using each_limit_all, which will guarantee all chunks have been uploaded properly.
                        $eachPromises = Promise\each_limit_all($promises, self::MAX_CONCURRENT_CHUNKS);
                        return $eachPromises->then(
                            function ($value) use ($uploadRequestInfo, $chunkNumber) {
                                return ['requestInfo' => $uploadRequestInfo, 'chunkNumber' => $chunkNumber];
                            });
                    } else {
                        throw new Exception("File not Found");
                    }
                }
            )
            ->then(
                function ($value) {
                    return $this->finalizeUploadAsync($value['requestInfo'], $value['chunkNumber']);
                }
            )
            ->then(
                function ($finalizeResponse) {
                    return $this->hasFinishedSuccessfullyAsync($finalizeResponse)
                        ->then(
                            function ($response) use ($finalizeResponse) {
                                return [
                                    'pollStatus' => $response,
                                    'finalizeData' => $finalizeResponse
                                ];
                            });
                }
            )
            ->then(
                function ($value) use ($data) {
                    if ($value['pollStatus'] != false) {
                        $data['importId'] = $value['finalizeData']['importId'];
                        return $this->saveMediaAsync($data);
                    } else {
                        throw new Exception("Converter did not finish. Upload failed.");
                    }
                }
            );

        return $uploadedFilePromise;
    }
public function uploadFile ( $ data ) { $ uploadedFilePromise = $ this -> getClosestUploadEndpoint ( ) -> then ( function ( ) use ( $ data ) { return $ this -> requestUploadInformationAsync ( $ data [ 'filePath' ] ) ; } ) -> then ( function ( $ uploadRequestInfo ) use ( $ data ) { if ( $ file = fopen ( $ data [ 'filePath' ] , 'rb' ) ) { $ fileSize = filesize ( $ data [ 'filePath' ] ) ; $ numberOfChunks = round ( ( $ fileSize + self :: CHUNK_SIZE - 1 ) / self :: CHUNK_SIZE ) ; $ chunkNumber = 0 ; // This is where the magic happens. We create all the promises via an Iterator function. $ promises = $ this -> uploadChunkIterator ( $ file , $ data [ 'filePath' ] , $ uploadRequestInfo , $ numberOfChunks , $ chunkNumber ) ; // After that we batch them all together using each_limit_all, which will guarantee all chunks have been uploaded properly. $ eachPromises = Promise \ each_limit_all ( $ promises , self :: MAX_CONCURRENT_CHUNKS ) ; return $ eachPromises -> then ( function ( $ value ) use ( $ uploadRequestInfo , $ chunkNumber ) { return [ 'requestInfo' => $ uploadRequestInfo , 'chunkNumber' => $ chunkNumber ] ; } ) ; } else { throw new Exception ( "File not Found" ) ; } } ) -> then ( function ( $ value ) { return $ this -> finalizeUploadAsync ( $ value [ 'requestInfo' ] , $ value [ 'chunkNumber' ] ) ; } ) -> then ( function ( $ finalizeResponse ) { return $ this -> hasFinishedSuccessfullyAsync ( $ finalizeResponse ) -> then ( function ( $ response ) use ( $ finalizeResponse ) { return [ 'pollStatus' => $ response , 'finalizeData' => $ finalizeResponse ] ; } ) ; } ) -> then ( function ( $ value ) use ( $ data ) { if ( $ value [ 'pollStatus' ] != false ) { $ data [ 'importId' ] = $ value [ 'finalizeData' ] [ 'importId' ] ; return $ this -> saveMediaAsync ( $ data ) ; } else { throw new Exception ( "Converter did not finish. Upload failed." ) ; } } ) ; return $ uploadedFilePromise ; }
Uploads a file with the data specified in the data parameter.

Client requests S3-upload endpoint information from the Bynder API.
For each file the client needs to requests upload authorization from the Bynder API.
The client uploads a file chunked with CORS directly to the Amazon S3 endpoint received in step 1.
Each chunk is named "FIXED_PREFIX/p{PARTNUMBER}", the partnumber needs to be sequentially updated.
Each chunk needs to be registered as completed using a request to Bynder.
When the file is completely uploaded, the client sends a “finalise” request to Bynder.
After the file is processed, the client sends a “save” call to save the file in Bynder.
Additional information can be provided such as title, tags, metadata and description.

@param $data array containing the file and media asset information.

@return Promise\Promise file promise.
@throws Exception
Uploads a file with the data specified in the data parameter .