UNPKG

1.62 kBJavaScriptView Raw
1"use strict";
2/**
3 * Copyright 2013 Vimeo
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18var Vimeo = require('../index').Vimeo;
19
20try {
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
28var lib = new Vimeo(config.client_id, config.client_secret);
29if (!config.access_token) {
30 throw new Error('You can not upload a video without configuring an access token');
31}
32
33// The file to upload should be passed in as the first argument to this script
34var file_path = process.argv[2];
35
36lib.access_token = config.access_token;
37lib.streamingUpload(file_path, function (err, body, status, headers) {
38 if (err) {
39 return console.log(err);
40 }
41 console.log(status);
42 console.log(headers.location);
43});