src/Proxy/UploadSessionProxy.php
public function complete()
    {
        $stream = $this->content instanceof Stream ?
            $this->content
            : Psr7\stream_for($this->content);

        if ($this->rangeSize !== null) {
            $rangeSize = $this->rangeSize;
            $rangeSize = $rangeSize - $rangeSize % self::RANGE_SIZE_MULTIPLE;
            $rangeSize = min($rangeSize, self::MAX_RANGE_SIZE);
            $rangeSize = max($rangeSize, self::MIN_RANGE_SIZE);
        } else {
            $rangeSize = self::RANGE_SIZE_MULTIPLE;
        }

        $size   = $stream->getSize();
        $offset = 0;

        while (!$stream->eof()) {
            $rangeStream = new LimitStream($stream, $rangeSize, $offset);
            $rangeSize   = $rangeStream->getSize();
            $body        = $rangeStream->getContents();
            $rangeFirst  = $offset;
            $offset += $rangeSize;
            $rangeLast = $offset - 1;

            $headers = [
                'Content-Length' => $rangeSize,
                'Content-Range'  => "bytes $rangeFirst-$rangeLast/$size",
            ];

            if ($this->type !== null) {
                $headers['Content-Type'] = $this->type;
            }

            $response = $this
                ->graph
                ->createRequest('PUT', $this->uploadUrl)
                ->addHeaders($headers)
                ->attachBody($body)
                ->execute();

            $status = $response->getStatus();

            if ($status == 200 || $status == 201) {
                $driveItem = $response->getResponseAsObject(DriveItem::class);

                return new DriveItemProxy($this->graph, $driveItem);
            }

            if ($status != 202) {
                throw new \Exception("Unexpected status code produced by 'PUT {$this->uploadUrl}': $status");
            }
        }

        throw new \Exception('OneDrive did not create a drive item for the uploaded file');
    }
public function complete()
    {
        $stream = $this->content instanceof Stream ?
            $this->content
            : Psr7\stream_for($this->content);

        if ($this->rangeSize !== null) {
            $rangeSize = $this->rangeSize;
            $rangeSize = $rangeSize - $rangeSize % self::RANGE_SIZE_MULTIPLE;
            $rangeSize = min($rangeSize, self::MAX_RANGE_SIZE);
            $rangeSize = max($rangeSize, self::MIN_RANGE_SIZE);
        } else {
            $rangeSize = self::RANGE_SIZE_MULTIPLE;
        }

        $size   = $stream->getSize();
        $offset = 0;

        while (!$stream->eof()) {
            $rangeStream = new LimitStream($stream, $rangeSize, $offset);
            $rangeSize   = $rangeStream->getSize();
            $body        = $rangeStream->getContents();
            $rangeFirst  = $offset;
            $offset += $rangeSize;
            $rangeLast = $offset - 1;

            $headers = [
                'Content-Length' => $rangeSize,
                'Content-Range'  => "bytes $rangeFirst-$rangeLast/$size",
            ];

            if ($this->type !== null) {
                $headers['Content-Type'] = $this->type;
            }

            $response = $this
                ->graph
                ->createRequest('PUT', $this->uploadUrl)
                ->addHeaders($headers)
                ->attachBody($body)
                ->execute();

            $status = $response->getStatus();

            if ($status == 200 || $status == 201) {
                $driveItem = $response->getResponseAsObject(DriveItem::class);

                return new DriveItemProxy($this->graph, $driveItem);
            }

            if ($status != 202) {
                throw new \Exception("Unexpected status code produced by 'PUT {$this->uploadUrl}': $status");
            }
        }

        throw new \Exception('OneDrive did not create a drive item for the uploaded file');
    }
public function complete ( ) { $ stream = $ this -> content instanceof Stream ? $ this -> content : Psr7 \ stream_for ( $ this -> content ) ; if ( $ this -> rangeSize !== null ) { $ rangeSize = $ this -> rangeSize ; $ rangeSize = $ rangeSize - $ rangeSize % self :: RANGE_SIZE_MULTIPLE ; $ rangeSize = min ( $ rangeSize , self :: MAX_RANGE_SIZE ) ; $ rangeSize = max ( $ rangeSize , self :: MIN_RANGE_SIZE ) ; } else { $ rangeSize = self :: RANGE_SIZE_MULTIPLE ; } $ size = $ stream -> getSize ( ) ; $ offset = 0 ; while ( ! $ stream -> eof ( ) ) { $ rangeStream = new LimitStream ( $ stream , $ rangeSize , $ offset ) ; $ rangeSize = $ rangeStream -> getSize ( ) ; $ body = $ rangeStream -> getContents ( ) ; $ rangeFirst = $ offset ; $ offset += $ rangeSize ; $ rangeLast = $ offset - 1 ; $ headers = [ 'Content-Length' => $ rangeSize , 'Content-Range' => "bytes $rangeFirst-$rangeLast/$size" , ] ; if ( $ this -> type !== null ) { $ headers [ 'Content-Type' ] = $ this -> type ; } $ response = $ this -> graph -> createRequest ( 'PUT' , $ this -> uploadUrl ) -> addHeaders ( $ headers ) -> attachBody ( $ body ) -> execute ( ) ; $ status = $ response -> getStatus ( ) ; if ( $ status == 200 || $ status == 201 ) { $ driveItem = $ response -> getResponseAsObject ( DriveItem :: class ) ; return new DriveItemProxy ( $ this -> graph , $ driveItem ) ; } if ( $ status != 202 ) { throw new \ Exception ( "Unexpected status code produced by 'PUT {$this->uploadUrl}': $status" ) ; } } throw new \ Exception ( 'OneDrive did not create a drive item for the uploaded file' ) ; }
Uploads the content in multiple ranges and completes this session.

@return DriveItemProxy
The drive item created.

@todo Support retries on errors.
Uploads the content in multiple ranges and completes this session .