Upload new captions file for a video
Requestβ
- Method:
POST
- URL:
https://dev.vdocipher.com/api/videos/{videoId}/files/
- Content-type:
multipart/form-data
- Input params:
type | name | description |
---|---|---|
query | language | ISO 639-1 representation of the language |
http-form | file | vtt file packaged as a multipart-formdata |
- Nodejs
- Golang
const fs = require('fs');
const rp = require('request-promise-native');
// replace with your values
const videoId = '_______';
const filePath = './path/to/file.vtt';
const authHeader = {
authorization: `Apisecret ${process.env.apisecret}`,
};
const uploadSubtitle = (videoId, filePath, language) => {
return rp({
url: `https://dev.vdocipher.com/api/videos/${videoId}/files/`,
method: 'POST',
qs: {language: language},
headers: {
'Content-type': 'multipart/form-data',
...authHeader,
},
formData: {
file: {
value: fs.createReadStream(filePath),
options: {},
},
},
json: true,
});
};
uploadSubtitle(videoId, filePath, 'en')
.then(console.log)
.catch((e) => {
if (!e.statusCode) {
throw e;
}
console.error(e.message);
});
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
"path/filepath"
)
func upload(file *os.File, videoId string, language string) (*http.Response, error) {
APIKEY := "Apisecret <put_your_api_secret_here>" //remove angular brackets after pasting your api key here
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, _ := writer.CreateFormFile("file", filepath.Base(file.Name()))
_, err := io.Copy(part, file)
writer.Close()
if err != nil {
return nil, err
}
url := fmt.Sprintf("https://dev.vdocipher.com/api/videos/%s/files?language=%s", videoId, language)
request, err := http.NewRequest(http.MethodPost, url, body)
if err != nil {
return nil, err
}
request.Header.Add("Content-Type", writer.FormDataContentType())
request.Header.Add("authorization", APIKEY)
client := &http.Client{}
res, err := client.Do(request)
if err != nil {
return nil, err
}
return res, nil
}
func main() {
file, _ := os.Open("yourVideoSubtitleFile.vtt") // For read access.
defer file.Close()
// replace with your video id
videoId := "your_video_id"
//replace "en" with the respective subtitle language
language := "en"
res, err := upload(file, videoId, language)
if err != nil {
fmt.Println(err)
// handle your error here
} else {
// handle your response here
fmt.Println(res)
}
}
Responseβ
Successβ
Content-type: application/json
key | type | description |
---|---|---|
id | integer | unique id of this uploaded file |
time | string | ISO8601 representation of upload time in UTC |
size | string | human readable format of size |
lang | string | ISO-639-1 representation of language |
{
"id": 12090067,
"time": "2021-04-04T09:06:26.925Z",
"size": "5 kB",
"lang": "en"
}