You are on page 1of 2

/**

* Upload by chunks - start phase


*
* @param string $endpoint
* @param FacebookFile $file
*
* @return FacebookTransferChunk
*
* @throws FacebookSDKException
*/
public function start($endpoint, FacebookFile $file)
{
$params = [
'upload_phase' => 'start',
'file_size' => $file->getSize(),
];
$response = $this->sendUploadRequest($endpoint, $params);

return new FacebookTransferChunk($file, $response['upload_session_id'],


$response['video_id'], $response['start_offset'], $response['end_offset']);
}

/**
* Upload by chunks - transfer phase
*
* @param string $endpoint
* @param FacebookTransferChunk $chunk
* @param boolean $allowToThrow
*
* @return FacebookTransferChunk
*
* @throws FacebookResponseException
*/
public function transfer($endpoint, FacebookTransferChunk $chunk, $allowToThrow
= false)
{
$params = [
'upload_phase' => 'transfer',
'upload_session_id' => $chunk->getUploadSessionId(),
'start_offset' => $chunk->getStartOffset(),
'video_file_chunk' => $chunk->getPartialFile(),
];

try {
$response = $this->sendUploadRequest($endpoint, $params);
} catch (FacebookResponseException $e) {
$preException = $e->getPrevious();
if ($allowToThrow || !$preException instanceof
FacebookResumableUploadException) {
throw $e;
}

// Return the same chunk entity so it can be retried.


return $chunk;
}

return new FacebookTransferChunk($chunk->getFile(), $chunk-


>getUploadSessionId(), $chunk->getVideoId(), $response['start_offset'],
$response['end_offset']);
}

You might also like