/** * Triggers the upload process. * * @return array * @throws GoogleException */ public function upload() { $rangeStart = $this->rangeStart; $response = null; $resumeUri = $this->getResumeUri(); $size = $this->data->getSize() ?: '*'; do { $data = new LimitStream($this->data, $this->chunkSize ?: -1, $rangeStart); $rangeEnd = $rangeStart + ($data->getSize() - 1); $headers = ['Content-Length' => $data->getSize(), 'Content-Type' => $this->contentType, 'Content-Range' => "bytes {$rangeStart}-{$rangeEnd}/{$size}"]; $request = new Request('PUT', $resumeUri, $headers, $data); try { $response = $this->requestWrapper->send($request, $this->requestOptions); } catch (GoogleException $ex) { throw new GoogleException("Upload failed. Please use this URI to resume your upload: {$this->resumeUri}", $ex->getCode()); } $rangeStart = $this->getRangeStart($response->getHeaderLine('Range')); } while ($response->getStatusCode() === 308); return json_decode($response->getBody(), true); }
public function testLengthLessOffsetWhenNoLimitSize() { $a = Psr7\stream_for('foo_bar'); $b = new LimitStream($a, -1, 4); $this->assertEquals(3, $b->getSize()); }