Cheetah
FacebookResumableUploader.php
Go to the documentation of this file.
1 <?php
24 namespace Facebook\FileUpload;
25 
33 
40 {
44  protected $app;
45 
49  protected $accessToken;
50 
54  protected $client;
55 
59  protected $graphVersion;
60 
68  {
69  $this->app = $app;
70  $this->client = $client;
71  $this->accessToken = $accessToken;
72  $this->graphVersion = $graphVersion;
73  }
74 
85  public function start($endpoint, FacebookFile $file)
86  {
87  $params = [
88  'upload_phase' => 'start',
89  'file_size' => $file->getSize(),
90  ];
91  $response = $this->sendUploadRequest($endpoint, $params);
92 
93  return new FacebookTransferChunk($file, $response['upload_session_id'], $response['video_id'], $response['start_offset'], $response['end_offset']);
94  }
95 
107  public function transfer($endpoint, FacebookTransferChunk $chunk, $allowToThrow = false)
108  {
109  $params = [
110  'upload_phase' => 'transfer',
111  'upload_session_id' => $chunk->getUploadSessionId(),
112  'start_offset' => $chunk->getStartOffset(),
113  'video_file_chunk' => $chunk->getPartialFile(),
114  ];
115 
116  try {
117  $response = $this->sendUploadRequest($endpoint, $params);
118  } catch (FacebookResponseException $e) {
119  $preException = $e->getPrevious();
120  if ($allowToThrow || !$preException instanceof FacebookResumableUploadException) {
121  throw $e;
122  }
123 
124  // Return the same chunk entity so it can be retried.
125  return $chunk;
126  }
127 
128  return new FacebookTransferChunk($chunk->getFile(), $chunk->getUploadSessionId(), $chunk->getVideoId(), $response['start_offset'], $response['end_offset']);
129  }
130 
142  public function finish($endpoint, $uploadSessionId, $metadata = [])
143  {
144  $params = array_merge($metadata, [
145  'upload_phase' => 'finish',
146  'upload_session_id' => $uploadSessionId,
147  ]);
148  $response = $this->sendUploadRequest($endpoint, $params);
149 
150  return $response['success'];
151  }
152 
161  private function sendUploadRequest($endpoint, $params = [])
162  {
163  $request = new FacebookRequest($this->app, $this->accessToken, 'POST', $endpoint, $params, null, $this->graphVersion);
164 
165  return $this->client->sendRequest($request)->getDecodedBody();
166  }
167 }
Facebook\FileUpload\FacebookFile\getSize
getSize()
Definition: FacebookFile.php:143
Facebook\FileUpload\FacebookTransferChunk\getFile
getFile()
Definition: FacebookTransferChunk.php:79
Facebook\Exceptions\FacebookSDKException
Definition: FacebookSDKException.php:32
Facebook\FileUpload\FacebookResumableUploader\$graphVersion
$graphVersion
Definition: FacebookResumableUploader.php:59
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
php
Facebook\Authentication\AccessToken
Definition: AccessToken.php:32
Facebook\Exceptions\FacebookResumableUploadException
Definition: FacebookResumableUploadException.php:32
Facebook\FileUpload\FacebookResumableUploader\$app
$app
Definition: FacebookResumableUploader.php:44
Facebook\FileUpload\FacebookResumableUploader\start
start($endpoint, FacebookFile $file)
Definition: FacebookResumableUploader.php:85
Facebook\FileUpload\FacebookResumableUploader\$client
$client
Definition: FacebookResumableUploader.php:54
Facebook\Exceptions\FacebookResponseException
Definition: FacebookResponseException.php:34
Facebook\FileUpload
Definition: FacebookFile.php:24
Facebook\FileUpload\FacebookResumableUploader\$accessToken
$accessToken
Definition: FacebookResumableUploader.php:49
Facebook\FacebookApp
Definition: FacebookApp.php:30
Facebook\FileUpload\FacebookResumableUploader
Definition: FacebookResumableUploader.php:40
Facebook\FileUpload\FacebookResumableUploader\transfer
transfer($endpoint, FacebookTransferChunk $chunk, $allowToThrow=false)
Definition: FacebookResumableUploader.php:107
Facebook\FileUpload\FacebookResumableUploader\__construct
__construct(FacebookApp $app, FacebookClient $client, $accessToken, $graphVersion)
Definition: FacebookResumableUploader.php:67
Facebook\FileUpload\FacebookTransferChunk\getVideoId
getVideoId()
Definition: FacebookTransferChunk.php:129
Facebook\FacebookClient
Definition: FacebookClient.php:37
Facebook\FileUpload\FacebookResumableUploader\finish
finish($endpoint, $uploadSessionId, $metadata=[])
Definition: FacebookResumableUploader.php:142
Facebook\FileUpload\FacebookTransferChunk\getUploadSessionId
getUploadSessionId()
Definition: FacebookTransferChunk.php:101
Facebook\FileUpload\FacebookTransferChunk
Definition: FacebookTransferChunk.php:32
Facebook\FileUpload\FacebookTransferChunk\getPartialFile
getPartialFile()
Definition: FacebookTransferChunk.php:89
Facebook\FileUpload\FacebookTransferChunk\getStartOffset
getStartOffset()
Definition: FacebookTransferChunk.php:119
Facebook\FacebookRequest
Definition: FacebookRequest.php:40
Facebook\FileUpload\FacebookFile
Definition: FacebookFile.php:34