Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nodejs) upload with token and videoId #61

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
- name: Install dependancies
uses: php-actions/composer@v5
with:
php_version: 7.3
php_version: 8.1
- name: PHPUnit tests
uses: php-actions/phpunit@v2
env:
API_KEY: ${{ secrets.API_KEY }}
BASE_URI: https://sandbox.api.video
with:
args: tests
args: tests --log-junit output.xml
6 changes: 3 additions & 3 deletions src/VideoUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function uploadWithUploadToken(string $token, \SplFileObject $file, strin
return $this->execute(
'/upload?token='.$token,
$file,
$this->getChunkSize($contentRange)
$this->getChunkSize($contentRange),
$videoId
);
}

Expand All @@ -65,14 +66,13 @@ public function uploadWithUploadToken(string $token, \SplFileObject $file, strin
* @return Video
* @throws ClientExceptionInterface
*/
private function execute(string $path, \SplFileObject $file, int $chunkSize): Video
private function execute(string $path, \SplFileObject $file, int $chunkSize, string $videoId = null): Video
{
$start = 0;
$fileSize = filesize($file->getRealPath());
$handle = fopen($file->getRealPath(), 'r');

$response = null;
$videoId = null;
$part = 1;
$partsCount = ceil($fileSize / $chunkSize);

Expand Down
29 changes: 29 additions & 0 deletions tests/Api/VideosApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,33 @@ public function testUploadThumbnail()
$this->assertEquals('thumbnail.jpg', basename($video->getAssets()->getThumbnail()));
}

public function testUploadWithUploadTokenWithVideoId()
{
$token = (new Helper($this->client))->createUploadToken();

$video = $this->client->videos()->create((new VideoCreationPayload())
->setTitle('Test video creation')
->setDescription('Test description'));

// No authorization needed for this endpoint
$client = new Client(
$_ENV['BASE_URI'],
null,
new Psr18Client()
);

$uploadedVideo = $client->videos()->uploadWithUploadToken(
$token->getToken(),
new SplFileObject(__DIR__ . '/../resources/558k.mp4'),
null,
$video->getVideoId()
);

$this->client->uploadTokens()->deleteToken($token->getToken());

$this->assertNotNull($uploadedVideo->getAssets()->getPlayer());
}

public function testUploadWithUploadToken()
{
$token = (new Helper($this->client))->createUploadToken();
Expand All @@ -274,6 +301,8 @@ public function testUploadWithUploadToken()
new SplFileObject(__DIR__ . '/../resources/558k.mp4')
);

$this->client->uploadTokens()->deleteToken($token->getToken());

$this->assertNotNull($uploadedVideo->getAssets()->getPlayer());
}
}