filestack/UploadProcessor.php
protected function processChunks($part, $chunks)
    {
        $upload_url = FilestackConfig::UPLOAD_URL . '/multipart/upload';
        $max_retries = FilestackConfig::MAX_RETRIES;

        $num_retries = 0;
        $promises = [];

        if (!array_key_exists('part_size', $part)) {
            $part['part_size'] = 0;
        }

        for($i=0; $i<count($chunks); $i++) {
            $current_chunk = $chunks[$i];
            $seek_point = $current_chunk['seek_point'];

            $chunk_content = $this->getChunkContent($part['filepath'], $seek_point,
                $current_chunk['size']);

            $current_chunk['md5'] = trim(base64_encode(md5($chunk_content, true)));
            $current_chunk['size'] = strlen($chunk_content);
            $part['part_size'] += $current_chunk['size'];

            $data = $this->buildChunkData($part, $current_chunk);
            $response = $this->sendRequest('POST', $upload_url, ['multipart' => $data]);

            try {
                $json = $this->handleResponseDecodeJson($response);
                $url = $json['url'];
                $headers = $json['headers'];

                $this->appendPromise($promises, 'PUT', $url, [
                    'body' => $chunk_content,
                    'headers' => $headers
                ]);
            }
            catch(FilestackException $e) {
                $status_code = $e->getCode();
                if ($this->intelligent && $num_retries < $max_retries) {
                    $num_retries++;
                    if (HttpStatusCodes::isServerError($status_code)) {
                        $wait_time = $this->get_retry_miliseconds($num_retries);
                        usleep($wait_time * 1000);
                    }

                    if (HttpStatusCodes::isNetworkError($status_code) ||
                        HttpStatusCodes::isServerError($status_code)) {
                        // reset index to retry this iteration
                        $i--;
                    }
                    continue;
                }

                throw new FilestackException($e->getMessage(), $status_code);
            }
        }

        return $promises;
    }
protected function processChunks($part, $chunks)
    {
        $upload_url = FilestackConfig::UPLOAD_URL . '/multipart/upload';
        $max_retries = FilestackConfig::MAX_RETRIES;

        $num_retries = 0;
        $promises = [];

        if (!array_key_exists('part_size', $part)) {
            $part['part_size'] = 0;
        }

        for($i=0; $i<count($chunks); $i++) {
            $current_chunk = $chunks[$i];
            $seek_point = $current_chunk['seek_point'];

            $chunk_content = $this->getChunkContent($part['filepath'], $seek_point,
                $current_chunk['size']);

            $current_chunk['md5'] = trim(base64_encode(md5($chunk_content, true)));
            $current_chunk['size'] = strlen($chunk_content);
            $part['part_size'] += $current_chunk['size'];

            $data = $this->buildChunkData($part, $current_chunk);
            $response = $this->sendRequest('POST', $upload_url, ['multipart' => $data]);

            try {
                $json = $this->handleResponseDecodeJson($response);
                $url = $json['url'];
                $headers = $json['headers'];

                $this->appendPromise($promises, 'PUT', $url, [
                    'body' => $chunk_content,
                    'headers' => $headers
                ]);
            }
            catch(FilestackException $e) {
                $status_code = $e->getCode();
                if ($this->intelligent && $num_retries < $max_retries) {
                    $num_retries++;
                    if (HttpStatusCodes::isServerError($status_code)) {
                        $wait_time = $this->get_retry_miliseconds($num_retries);
                        usleep($wait_time * 1000);
                    }

                    if (HttpStatusCodes::isNetworkError($status_code) ||
                        HttpStatusCodes::isServerError($status_code)) {
                        // reset index to retry this iteration
                        $i--;
                    }
                    continue;
                }

                throw new FilestackException($e->getMessage(), $status_code);
            }
        }

        return $promises;
    }
protected function processChunks ( $ part , $ chunks ) { $ upload_url = FilestackConfig :: UPLOAD_URL . '/multipart/upload' ; $ max_retries = FilestackConfig :: MAX_RETRIES ; $ num_retries = 0 ; $ promises = [ ] ; if ( ! array_key_exists ( 'part_size' , $ part ) ) { $ part [ 'part_size' ] = 0 ; } for ( $ i = 0 ; $ i < count ( $ chunks ) ; $ i ++ ) { $ current_chunk = $ chunks [ $ i ] ; $ seek_point = $ current_chunk [ 'seek_point' ] ; $ chunk_content = $ this -> getChunkContent ( $ part [ 'filepath' ] , $ seek_point , $ current_chunk [ 'size' ] ) ; $ current_chunk [ 'md5' ] = trim ( base64_encode ( md5 ( $ chunk_content , true ) ) ) ; $ current_chunk [ 'size' ] = strlen ( $ chunk_content ) ; $ part [ 'part_size' ] += $ current_chunk [ 'size' ] ; $ data = $ this -> buildChunkData ( $ part , $ current_chunk ) ; $ response = $ this -> sendRequest ( 'POST' , $ upload_url , [ 'multipart' => $ data ] ) ; try { $ json = $ this -> handleResponseDecodeJson ( $ response ) ; $ url = $ json [ 'url' ] ; $ headers = $ json [ 'headers' ] ; $ this -> appendPromise ( $ promises , 'PUT' , $ url , [ 'body' => $ chunk_content , 'headers' => $ headers ] ) ; } catch ( FilestackException $ e ) { $ status_code = $ e -> getCode ( ) ; if ( $ this -> intelligent && $ num_retries < $ max_retries ) { $ num_retries ++ ; if ( HttpStatusCodes :: isServerError ( $ status_code ) ) { $ wait_time = $ this -> get_retry_miliseconds ( $ num_retries ) ; usleep ( $ wait_time * 1000 ) ; } if ( HttpStatusCodes :: isNetworkError ( $ status_code ) || HttpStatusCodes :: isServerError ( $ status_code ) ) { // reset index to retry this iteration $ i -- ; } continue ; } throw new FilestackException ( $ e -> getMessage ( ) , $ status_code ) ; } } return $ promises ; }
Process the chunks of a part the file to server.

@param object    $part           the part to process
@param array     $chunks         the chunks of part to process

@throws FilestackException   if API call fails

@return Promises to send Asyncronously to s3
Process the chunks of a part the file to server .