Skip to content
Open
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
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/dist
/bower_components
/node_modules
npm-debug.log
.idea
package-lock.json
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

142 changes: 133 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,148 @@ npm install vimeo-upload
Include `vimeo-upload.js` in your index.html.

```
<script src="bower_components/vimeo-upload/vimeo-upload.js"></script>
<script src="bower_components/vimeo-upload/dist/vimeo-upload.min.js"></script>
```

Create a new `VimeoUpload` initialized with a Blob or File and Vimeo Access Token then call `upload()` to start the upload process.
### Basic:

Create a new `VimeoUpload` initialized with a Blob or File and Vimeo Access Token then call `start()` to start the upload process.

```javascript

var options = {
token: "TOKEN_STRING_HERE", //Required
file: null, //Required
videoData: {
name: "My awesome title", //Optional
description: "My awesome description" //Optional
}
}

var uploader = new VimeoUpload();
uploader.start(options);

```

### Advanced:

#### All default properties

List of options that can be overriden.

```
| Properties | Description | Default | Required |
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|----------|
| token | Authentication token created on Vimeo, must have an UPLOAD scope (to be able to upload), and an EDIT scope(to add meta data after upload is complete) | YOUR_TOKEN_HERE | Required |
| file | The File or Blog to upload. | null | Required |
| videoData | Object that supports all video data properties. See link for more info: https://developer.vimeo.com/api/endpoints/videos#PATCH/videos/{video_id} | {} | Optional
| preferredUploadDuration | The preferred chunk upload duration. The chunk size will be updated after each chunk upload to best fit the prefferedUploadDuration. | 20 [seconds] | Optional |
| chunkSize | The size of the chunk to be uploaded | 1024*1024 | Optional |
| supportedFiles | A list of supported file extensions. | ["mov", "mpeg4", "mp4", "avi", "wmv", "mpegps", "flv", "3gpp", "webm"] | Optional |
| upgrade_to_1080 | Upgrade the video to 1080 | false | Optional |
| timeInterval | Time interval for event data to be dispatched. | 150 [miliseconds] | Optional |
| maxAcceptedFails | The number of failures that can occur before the upload is terminated. Fails occur whenever a request fails. Setting this to 0 will allow for unlimited amount of fails. | 20 | Optional |
| maxAcceptedUploadDuration | If the maxAcceptedUploadDuration for a chunk is exceeded, the upload request is aborted and the chunkSize is updated before sending picking up where the upload was left. | 60 [seconds] | Optional |
| useDefaultFileName | Use the file's default name as the video name. | false | Optional |
| retryTimeout | The time before the upload process is resumed when a fail occurs. | 5000 [miliseconds] | Optional |
```

##### Usage


```javascript

//All Default options that can be overriden
var options = {
token: "TOKEN_STRING_HERE", //Required
file: null, //Required
videoData: {}, //Check link to see all supported properties | https://developer.vimeo.com/api/endpoints/videos#PATCH/videos/{video_id}
preferredUploadDuration: 20,
chunkSize: 1024*1024,
supportedFiles: ["mov", "mpeg4", "mp4", "avi", "wmv", "mpegps", "flv", "3gpp", "webm"],
upgrade_to_1080: false,
timeInterval: 150,
maxAcceptedFails: 20,
maxAcceptedUploadDuration: 60,
useDefaultFileName: false,
retryTimeout: 5000
};

var uploader = new VimeoUpload();
uploader.start(options);

```

#### Event Usage

##### List:

VimeoUpload comes with different events that can be binded.

```
| Event Names | Description | Frequency | [Object object] sent |
|----------------------|---------------------------------------------------------|---------------|-------------------------------------------------------------------------------------------|
| chunkprogresschanged | Regularly sends the current percent of a chunk upload | Default 150ms | { detail: number } |
| totalprogresschanged | Regularly sends the current percent of the total upload | Default 150ms | { detail: number } |
| vimeouploaderror | Emits if any errors occurs | N/A | { detail: { message: string, error: [Object object] } } |
| vimeouploadcomplete | Called once when the upload is completed | Once | { detail: { id: number, link: string, name: string, uri: string, createdTime: string } } |
```


##### Usage:
```javascript
var uploader = new VimeoUpload({
file: file,
token: accessToken,
});

uploader.upload();
//Get the progress bar elements
var totalProgress = document.getElementById("progress-total");
var chunkProgress = document.getElementById("progress-chunk");

//Create the VimeoUpload object
var vimeoUpload = new VimeoUpload();

vimeoUpload.on("chunkprogresschanged", function(event){
var progress = event.detail;
chunkProgress.setAttribute('style', 'width:' + progress + '%');
chunkProgress.innerHTML = '&nbsp;' + progress + '%'

});

vimeoUpload.on("totalprogresschanged", function(event){
var progress = event.detail;
totalProgress.setAttribute('style', 'width:' + progress + '%');
totalProgress.innerHTML = '&nbsp;' + progress + '%'
});

vimeoUpload.on("vimeouploaderror", function(event){
console.log(event.detail.message, event.detail.error);
});
id: vimeoId,
link: data.link,
name: data.name,
uri: data.uri,
createdTime: data.created_time
vimeoUpload.on("vimeouploadcomplete", function(event){

console.log("Meta data", event.detail);

//Properties returned
//var vimeoId = event.detail.id;
//var link = event.detail.link;
//var name = event.detail.name;
//var uri = event.detail.uri;
//var createdTime = event.detail.created_time;


});

//Start upload
vimeoUpload.start(options);

```

Your access token need to be authorized by Vimeo. Create new Vimeo access token [here](https://developer.vimeo.com/apps).
Your access token need to be authorized by Vimeo. Ensure it has an "EDIT" and "UPLOAD" scope. Create new Vimeo access token [here](https://developer.vimeo.com/apps).

Check `index.html` for details and additional parameters you can include when initializing `VimeoUpload`.

## Credits

Sample code for uploading files directly with XHR/CORS: [cors-upload-sample](https://github.com/googledrive/cors-upload-sample)
Sample code for uploading files directly with XHR/CORS: [cors-upload-sample](https://github.com/googledrive/cors-upload-sample)
24 changes: 0 additions & 24 deletions bower.json

This file was deleted.

Loading