public function testCanCreateEmptyStream() { $b = new MultipartStream(); $boundary = $b->getBoundary(); $this->assertSame("--{$boundary}--\r\n", $b->getContents()); $this->assertSame(strlen($boundary) + 6, $b->getSize()); }
/** * Triggers the upload process. * * @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); }