jsonDecode( $this->requestWrapper->send( $this->prepareRequest(), $this->requestOptions )->getBody(), true ); } /** * Triggers the upload process asynchronously. * * @return PromiseInterface * @experimental The experimental flag means that while we believe this method * or class is ready for use, it may change before release in backwards- * incompatible ways. Please use with caution, and test thoroughly when * upgrading. */ public function uploadAsync() { return $this->requestWrapper->sendAsync( $this->prepareRequest(), $this->requestOptions )->then(function (ResponseInterface $response) { return $this->jsonDecode( $response->getBody(), true ); }); } /** * Prepares a multipart upload request. * * @return RequestInterface */ private function prepareRequest() { $multipartStream = new Psr7\MultipartStream([ [ 'name' => 'metadata', 'headers' => ['Content-Type' => 'application/json; charset=UTF-8'], 'contents' => $this->jsonEncode($this->metadata) ], [ 'name' => 'data', 'headers' => ['Content-Type' => $this->contentType], 'contents' => $this->data ] ], 'boundary'); $headers = [ 'Content-Type' => 'multipart/related; boundary=boundary', ]; $size = $multipartStream->getSize(); if ($size !== null) { $headers['Content-Length'] = $size; } return new Request( 'POST', $this->uri, $headers, $multipartStream ); } }