Skip to content

Commit 285b979

Browse files
perform_tus_upload: allow overriding default per-PATCH chunk size
The default value of 100MB may not be usable for clients with slow upload speeds. Allow configuring this value per-upload-call.
1 parent d3c49b7 commit 285b979

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/Vimeo/Vimeo.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,12 @@ public function buildAuthorizationEndpoint($redirect_uri, $scope = 'public', $st
314314
* @link https://developer.vimeo.com/api/endpoints/videos#POST/users/{user_id}/videos
315315
* @param string $file_path Path to the video file to upload.
316316
* @param array $params Parameters to send when creating a new video (name, privacy restrictions, etc.).
317+
* @param int|null $override_chunk_size Optionally override the default chunk size of 100MB.
317318
* @return string Video URI
318319
* @throws VimeoRequestException
319320
* @throws VimeoUploadException
320321
*/
321-
public function upload($file_path, array $params = array())
322+
public function upload($file_path, array $params = array(), ?int $override_chunk_size = null)
322323
{
323324
// Validate that our file is real.
324325
if (!is_file($file_path)) {
@@ -340,7 +341,7 @@ public function upload($file_path, array $params = array())
340341
throw new VimeoUploadException('Unable to initiate an upload.' . $attempt_error);
341342
}
342343

343-
return $this->perform_upload_tus($file_path, $file_size, $attempt);
344+
return $this->perform_upload_tus($file_path, $file_size, $attempt, $override_chunk_size);
344345
}
345346

346347
/**
@@ -349,11 +350,12 @@ public function upload($file_path, array $params = array())
349350
* @link https://developer.vimeo.com/api/endpoints/videos#POST/videos/{video_id}/versions
350351
* @param string $video_uri Video uri of the video file to replace.
351352
* @param string $file_path Path to the video file to upload.
353+
* @param int|null $override_chunk_size Optionally override the default chunk size of 100MB.
352354
* @return string Video URI
353355
* @throws VimeoRequestException
354356
* @throws VimeoUploadException
355357
*/
356-
public function replace($video_uri, $file_path, array $params = array())
358+
public function replace($video_uri, $file_path, array $params = array(), ?int $override_chunk_size = null)
357359
{
358360
// Validate that our file is real.
359361
if (!is_file($file_path)) {
@@ -379,7 +381,7 @@ public function replace($video_uri, $file_path, array $params = array())
379381
// `uri` doesn't come back from `/videos/:id/versions` so we need to manually set it here for uploading.
380382
$attempt['body']['uri'] = $video_uri;
381383

382-
return $this->perform_upload_tus($file_path, $file_size, $attempt);
384+
return $this->perform_upload_tus($file_path, $file_size, $attempt, $override_chunk_size);
383385
}
384386

385387
/**
@@ -576,12 +578,16 @@ private function _authHeader(): string
576578
* @param string $file_path Path to the video file to upload.
577579
* @param int|float $file_size Size of the video file.
578580
* @param array $attempt Upload attempt data.
581+
* @param int|null $override_chunk_size Optionally override the default chunk size of 100MB.
579582
* @return string
580583
* @throws VimeoUploadException
581584
*/
582-
private function perform_upload_tus(string $file_path, $file_size, array $attempt): string
585+
private function perform_upload_tus(string $file_path, $file_size, array $attempt, ?int $override_chunk_size = null): string
583586
{
584587
$default_chunk_size = (100 * 1024 * 1024); // 100 MB
588+
if ($override_chunk_size) {
589+
$default_chunk_size = $override_chunk_size;
590+
}
585591

586592
$url = $attempt['body']['upload']['upload_link'];
587593
$url_path = parse_url($url)['path'];

0 commit comments

Comments
 (0)