Google\Cloud\Upload\MultipartUploader::upload PHP Method

upload() public method

Triggers the upload process.
public upload ( ) : array
return array
    public function upload()
    {
        $multipartStream = new Psr7\MultipartStream([['name' => 'metadata', 'headers' => ['Content-Type' => 'application/json; charset=UTF-8'], 'contents' => json_encode($this->metadata)], ['name' => 'data', 'headers' => ['Content-Type' => $this->contentType], 'contents' => $this->data]], 'boundary');
        $headers = ['Content-Type' => 'multipart/related; boundary=boundary', 'Content-Length' => $multipartStream->getSize()];
        return json_decode($this->requestWrapper->send(new Request('POST', $this->uri, $headers, $multipartStream), $this->requestOptions)->getBody(), true);
    }

Usage Example

 public function testUploadsData()
 {
     $requestWrapper = $this->prophesize('Google\\Cloud\\RequestWrapper');
     $stream = Psr7\stream_for('abcd');
     $successBody = '{"canI":"kickIt"}';
     $response = new Response(200, [], $successBody);
     $requestWrapper->send(Argument::type('Psr\\Http\\Message\\RequestInterface'), Argument::type('array'))->willReturn($response);
     $uploader = new MultipartUploader($requestWrapper->reveal(), $stream, 'http://www.example.com');
     $this->assertEquals(json_decode($successBody, true), $uploader->upload());
 }
MultipartUploader