Skip to content

Commit e753306

Browse files
committed
Update README
1 parent e20dd20 commit e753306

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

README.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# api.video video uploader
44

5-
Typescript library to upload videos to api.video using delegated token
5+
Typescript library to upload videos to api.video using delegated token (or usual access token) from front-end.
66

77
# Usage
88

@@ -73,3 +73,83 @@ Then, once the `window.onload` event has been trigered, create your player using
7373
}
7474
</script>
7575
```
76+
77+
# Instanciation
78+
79+
## Options
80+
81+
The upload is instanciated using an `options` object. Options to provide depend on the way you want to authenticate to the API: either using a delegated upload token (recommanded), or using a usual access token.
82+
83+
### Using a delegated token:
84+
85+
86+
| Option name | Mandatory | Type | Description |
87+
| ----------------------------: | --------- | ------ | ----------------- |
88+
| uploadToken | **yes** | string | your upload token |
89+
| _common options (see bellow)_ | | | |
90+
91+
92+
### Using an access token:
93+
94+
95+
| Option name | Mandatory | Type | Description |
96+
| ----------------------------: | --------- | ------ | ----------------------- |
97+
| accessToken | **yes** | string | your access token |
98+
| videoId | **yes** | string | id of an existing video |
99+
| _common options (see bellow)_ | | | |
100+
101+
102+
### Common options
103+
104+
105+
| Option name | Mandatory | Type | Description |
106+
| ----------: | --------- | ------ | ----------------------------------------------------- |
107+
| file | yes | File | the file you want to upload |
108+
| chunkSize | no | number | number of bytes of each upload chunk (default: 1MB) |
109+
| apiHost | no | string | api.video host (default: ws.api.video) |
110+
| retries | no | number | number of retries when an API call fails (default: 5) |
111+
112+
113+
## Example
114+
115+
```javascript
116+
const uploader = new VideoUploader({
117+
file: files[0],
118+
uploadToken: "YOUR_DELEGATED_TOKEN",
119+
chunkSize: 1024*1024*10, // 10MB
120+
retries: 10,
121+
});
122+
```
123+
124+
# Methods
125+
126+
## `upload()`
127+
128+
The upload() method starts the upload. It takes no parameter. It returns a Promise that resolves once the file is uploaded. If an API call fails more than the specified number of retries, then the promise is rejected.
129+
On success, the promise embeds the `video` object returned by the API.
130+
On fail, the promise embeds the status code & error message returned by the API.
131+
132+
### Example
133+
134+
```javascript
135+
// ... uploader instanciation
136+
137+
uploader.upload()
138+
.then((video) => console.log(video))
139+
.catch((error) => console.log(error.status, error.message));
140+
```
141+
142+
## `onProgress()`
143+
144+
The onProgress() method let you defined an upload progress listener. It takes a callback function with one parameter: the onProgress events.
145+
An onProgress event contains 2 attributes:
146+
- loaded: the number of uploaded bytes
147+
- total: the total number of bytes
148+
149+
### Example
150+
151+
```javascript
152+
// ... uploader instanciation
153+
154+
uploader.onProgress((event) => console.log(event.loaded, event.total));
155+
```

0 commit comments

Comments
 (0)