1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var Vimeo = require('../index').Vimeo;
|
19 |
|
20 | try {
|
21 | var config = require('./config.json');
|
22 | } catch (error) {
|
23 | console.error('ERROR: For this example to run properly you must create an api app at developer.vimeo.com/apps/new and set your callback url to http://localhost:8080/oauth_callback');
|
24 | console.error('ERROR: Once you have your app, make a copy of config.json.example named "config.json" and add your client id, client secret and access token');
|
25 | return;
|
26 | }
|
27 |
|
28 | var lib = new Vimeo(config.client_id, config.client_secret);
|
29 | if (!config.access_token) {
|
30 | throw new Error('You can not upload a video without configuring an access token');
|
31 | }
|
32 |
|
33 |
|
34 | var file_path = process.argv[2];
|
35 |
|
36 |
|
37 |
|
38 | var prev_percentage = -1;
|
39 |
|
40 | lib.access_token = config.access_token;
|
41 | lib.streamingUpload(file_path,
|
42 | function (err, body, status, headers) {
|
43 | if (err) {
|
44 | return console.log(err);
|
45 | }
|
46 | console.log(status);
|
47 | console.log(headers.location);
|
48 | },
|
49 | function (uploaded_size, file_size) {
|
50 | var percentage = Math.round((uploaded_size/file_size) * 100);
|
51 |
|
52 | if (percentage != prev_percentage) {
|
53 | console.log(percentage + '%' + ' uploaded\n');
|
54 | prev_percentage = percentage;
|
55 | }
|
56 | }
|
57 | );
|