Repository navigation
Expand file tree
/
Copy pathupload-large-video.php
More file actions
60 lines (50 loc) · 1.84 KB
/
Copy pathupload-large-video.php
File metadata and controls
60 lines (50 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Upload a video. Files above chunk_size (20 MB by default) are chunked automatically —
* there is no separate large-upload method in this SDK.
*
* Prerequisites:
* composer require cloudinary/cloudinary_php
* export CLOUDINARY_URL=cloudinary://<api_key>:<api_secret>@<cloud_name>
*
* Run:
* php examples/upload-large-video.php
*
* In your own project, the import and instantiation are:
* require 'vendor/autoload.php';
* use Cloudinary\Cloudinary;
* $cloudinary = new Cloudinary();
*/
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use Cloudinary\Cloudinary;
const SOURCE_VIDEO = 'https://res.cloudinary.com/demo/video/upload/dog.mp4';
const PUBLIC_ID = 'examples/upload-large-video';
function main(): void
{
$cloudinary = new Cloudinary();
// resource_type is required: upload() defaults to 'image' and a video without this
// option fails with "BadRequest: Invalid image file".
$result = $cloudinary->uploadApi()->upload(
SOURCE_VIDEO,
[
'resource_type' => 'video',
'public_id' => PUBLIC_ID,
'tags' => ['example'],
]
);
echo 'Uploaded: ', $result['public_id'], PHP_EOL;
echo 'Duration: ', $result['duration'], ' seconds', PHP_EOL;
echo 'Size: ', $result['width'], 'x', $result['height'], ' ', $result['format'], PHP_EOL;
echo 'Bytes: ', $result['bytes'], PHP_EOL;
echo 'URL: ', $result['secure_url'], PHP_EOL;
// Chunking threshold currently in effect.
echo 'Chunk size: ', $cloudinary->configuration->api->chunkSize, ' bytes', PHP_EOL;
}
try {
main();
} catch (Throwable $e) {
fwrite(STDERR, 'Video upload failed: ' . $e->getMessage() . PHP_EOL);
fwrite(STDERR, 'Check that CLOUDINARY_URL is set (Console > Settings > API Keys).' . PHP_EOL);
exit(1);
}