Skip to content

Commit 3b4a6cf

Browse files
author
Ian Barber
committed
Adding http upload code to MediaFileUpload
Addresses googleapis#74
1 parent 277e6ba commit 3b4a6cf

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Google/Http/MediaFileUpload.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class Google_Http_MediaFileUpload
6161
/** @var string */
6262
private $boundary;
6363

64+
/**
65+
* Result code from last HTTP call
66+
* @var int
67+
*/
68+
private $httpResultCode;
69+
6470
/**
6571
* @param $mimeType string
6672
* @param $data string The bytes you want to upload.
@@ -112,6 +118,15 @@ public function getProgress()
112118
return $this->progress;
113119
}
114120

121+
/**
122+
* Return the HTTP result code from the last call made.
123+
* @return int code
124+
*/
125+
public function getHttpResultCode()
126+
{
127+
return $this->httpResultCode;
128+
}
129+
115130
/**
116131
* Send the next part of the file to upload.
117132
* @param [$chunk] the next set of bytes to send. If false will used $data passed
@@ -151,6 +166,7 @@ public function nextChunk($chunk = false)
151166
$response = $this->client->getIo()->makeRequest($httpRequest);
152167
$response->setExpectedClass($this->request->getExpectedClass());
153168
$code = $response->getResponseHttpCode();
169+
$this->httpResultCode = $code;
154170

155171
if (308 == $code) {
156172
// Track the amount uploaded.

tests/general/ApiMediaFileUploadTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public function testGetUploadType() {
5151
$this->assertEquals('multipart',
5252
$media->getUploadType(array('a' => 'b')));
5353
}
54+
55+
public function testResultCode() {
56+
$client = $this->getClient();
57+
$request = new Google_Http_Request('http://www.example.com', 'POST');
58+
59+
// Test resumable upload
60+
$media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', true);
61+
$this->assertEquals(null, $media->getHttpResultCode());
62+
}
5463

5564
public function testProcess() {
5665
$client = $this->getClient();

0 commit comments

Comments
 (0)