Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 4f1c91f

Browse files
authored
Merge pull request #1001 from phaizullin/5.x
Fix resumable upload error "There was a problem uploading your video"
2 parents 2392804 + b4ee993 commit 4f1c91f

7 files changed

+89
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Version 5 of the Facebook PHP SDK is a complete refactor of version 4. It comes
1010
- Add `joined` to list of fields to be cast to `\DateTime` (#950)
1111
- Add `GraphPage::getFanCount()` to get the number of people who like the page (#815)
1212
- Fixed HTTP/2 support (#1079)
13+
- Fixed resumable upload error (#1001)
1314
- 5.6.3 (2018-07-01)
1415
- Add fix for countable error in PHP 7.2 (originally #969 by @andreybolonin)
1516
- 5.6.2 (2018-02-15)

src/Facebook/Exceptions/FacebookResponseException.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,20 @@ public static function create(FacebookResponse $response)
9090
// Video upload resumable error
9191
case 1363030:
9292
case 1363019:
93-
case 1363037:
9493
case 1363033:
9594
case 1363021:
9695
case 1363041:
9796
return new static($response, new FacebookResumableUploadException($message, $code));
97+
case 1363037:
98+
$previousException = new FacebookResumableUploadException($message, $code);
99+
100+
$startOffset = isset($data['error']['error_data']['start_offset']) ? (int) $data['error']['error_data']['start_offset'] : null;
101+
$previousException->setStartOffset($startOffset);
102+
103+
$endOffset = isset($data['error']['error_data']['end_offset']) ? (int) $data['error']['error_data']['end_offset'] : null;
104+
$previousException->setEndOffset($endOffset);
105+
106+
return new static($response, $previousException);
98107
}
99108
}
100109

src/Facebook/Exceptions/FacebookResumableUploadException.php

+35
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,39 @@
3030
*/
3131
class FacebookResumableUploadException extends FacebookSDKException
3232
{
33+
protected $startOffset;
34+
35+
protected $endOffset;
36+
37+
/**
38+
* @return int|null
39+
*/
40+
public function getStartOffset()
41+
{
42+
return $this->startOffset;
43+
}
44+
45+
/**
46+
* @param int|null $startOffset
47+
*/
48+
public function setStartOffset($startOffset)
49+
{
50+
$this->startOffset = $startOffset;
51+
}
52+
53+
/**
54+
* @return int|null
55+
*/
56+
public function getEndOffset()
57+
{
58+
return $this->endOffset;
59+
}
60+
61+
/**
62+
* @param int|null $endOffset
63+
*/
64+
public function setEndOffset($endOffset)
65+
{
66+
$this->endOffset = $endOffset;
67+
}
3368
}

src/Facebook/FileUpload/FacebookResumableUploader.php

+10
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ public function transfer($endpoint, FacebookTransferChunk $chunk, $allowToThrow
121121
throw $e;
122122
}
123123

124+
if (null !== $preException->getStartOffset() && null !== $preException->getEndOffset()) {
125+
return new FacebookTransferChunk(
126+
$chunk->getFile(),
127+
$chunk->getUploadSessionId(),
128+
$chunk->getVideoId(),
129+
$preException->getStartOffset(),
130+
$preException->getEndOffset()
131+
);
132+
}
133+
124134
// Return the same chunk entity so it can be retried.
125135
return $chunk;
126136
}

src/Facebook/FileUpload/FacebookTransferChunk.php

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ public function getStartOffset()
121121
return $this->startOffset;
122122
}
123123

124+
/**
125+
* @return int
126+
*/
127+
public function getEndOffset()
128+
{
129+
return $this->endOffset;
130+
}
131+
124132
/**
125133
* Get uploaded video Id
126134
*

tests/FileUpload/FacebookResumableUploaderTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,15 @@ public function testFailedResumableTransferWillNotThrowAndReturnSameChunk()
9898
$newChunk = $uploader->transfer('/me/videos', $chunk);
9999
$this->assertSame($newChunk, $chunk);
100100
}
101+
102+
public function testFailedResumableTransferWillNotThrowAndReturnNewChunk()
103+
{
104+
$this->graphApi->failOnTransferAndUploadNewChunk();
105+
$uploader = new FacebookResumableUploader($this->fbApp, $this->client, 'access_token', 'v2.4');
106+
107+
$chunk = new FacebookTransferChunk($this->file, '1', '2', '3', '4');
108+
$newChunk = $uploader->transfer('/me/videos', $chunk);
109+
$this->assertEquals(40, $newChunk->getStartOffset());
110+
$this->assertEquals(50, $newChunk->getEndOffset());
111+
}
101112
}

tests/Fixtures/FakeGraphApiForResumableUpload.php

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public function failOnTransfer()
4242
$this->respondWith = 'FAIL_ON_TRANSFER';
4343
}
4444

45+
public function failOnTransferAndUploadNewChunk()
46+
{
47+
$this->respondWith = 'FAIL_ON_TRANSFER_AND_UPLOAD_NEW_CHUNK';
48+
}
49+
4550
public function send($url, $method, $body, array $headers, $timeOut)
4651
{
4752
// Could be start, transfer or finish
@@ -81,6 +86,15 @@ private function respondTransfer()
8186
);
8287
}
8388

89+
if ($this->respondWith == 'FAIL_ON_TRANSFER_AND_UPLOAD_NEW_CHUNK') {
90+
return new GraphRawResponse(
91+
"HTTP/1.1 500 OK\r\nFoo: Bar",
92+
'{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",' .
93+
'"type":"OAuthException","code":6001,"error_subcode":1363037,' .
94+
'"error_data":{"start_offset":40,"end_offset":50}}}'
95+
);
96+
}
97+
8498
switch ($this->transferCount) {
8599
case 0:
86100
$data = ['start_offset' => 20, 'end_offset' => 40];

0 commit comments

Comments
 (0)