import os
from gcore import Gcore
client = Gcore(
api_key=os.environ.get("GCORE_API_KEY"), # This is the default and can be omitted
)
direct_upload_parameters = client.streaming.videos.get_parameters_for_direct_upload(
0,
)
print(direct_upload_parameters.video)package main
import (
"context"
"fmt"
"github.com/G-Core/gcore-go"
"github.com/G-Core/gcore-go/option"
)
func main() {
client := gcore.NewClient(
option.WithAPIKey("My API Key"),
)
directUploadParameters, err := client.Streaming.Videos.GetParametersForDirectUpload(context.TODO(), 0)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", directUploadParameters.Video)
}
curl --request GET \
--url https://api.gcore.com/streaming/videos/{video_id}/upload \
--header 'Authorization: <api-key>'const options = {method: 'GET', headers: {Authorization: '<api-key>'}};
fetch('https://api.gcore.com/streaming/videos/{video_id}/upload', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gcore.com/streaming/videos/{video_id}/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://api.gcore.com/streaming/videos/{video_id}/upload")
.header("Authorization", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gcore.com/streaming/videos/{video_id}/upload")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"servers": [
{
"id": 15,
"hostname": "example.com"
}
],
"token": "X2lkIjoxMDE1fSwi",
"video": {
"id": 17,
"name": "Video",
"description": "Conference July",
"client_id": 100,
"duration": 4120,
"slug": "zInSg1FL80",
"origin_size": 2974741,
"origin_host": "origin.host.org",
"origin_resource": "",
"origin_height": 1080,
"screenshots": [
"https://screenshot1.example.com/494.jpg"
],
"screenshot_id": 0,
"ad_id": 2,
"projection": "regular",
"client_user_id": 10,
"hls_url": "https://example.com/master.m3u8"
}
}Get TUS' parameters for direct upload
Use this method to get TUS’ session parameters: hostname of the server to upload, secure token.
The general sequence of actions for a direct upload of a video is as follows:
- Create video entity via POST method “Create video”
- Get TUS’ session parameters (you are here now)
- Upload file via TUS client, choose your implementation on tus.io
Final endpoint for uploading is constructed using the following template: “https:///upload/”. Also you have to provide token, client_id, video_id as metadata too.
A short javascript example is shown below, based on tus-js-client. Variable “data” below is the result of this API request. Please, note that we support 2.x version only of tus-js-client.
uploads[data.video.id] = new tus.Upload(file, {
endpoint: `https://${data.servers[0].hostname}/upload/`,
metadata: {
filename: data.video.name,
token: data.token,
video_id: data.video.id,
client_id: data.video.client_id
},
onSuccess: function() {
...
}
}
uploads[data.video.id].start();
import os
from gcore import Gcore
client = Gcore(
api_key=os.environ.get("GCORE_API_KEY"), # This is the default and can be omitted
)
direct_upload_parameters = client.streaming.videos.get_parameters_for_direct_upload(
0,
)
print(direct_upload_parameters.video)package main
import (
"context"
"fmt"
"github.com/G-Core/gcore-go"
"github.com/G-Core/gcore-go/option"
)
func main() {
client := gcore.NewClient(
option.WithAPIKey("My API Key"),
)
directUploadParameters, err := client.Streaming.Videos.GetParametersForDirectUpload(context.TODO(), 0)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", directUploadParameters.Video)
}
curl --request GET \
--url https://api.gcore.com/streaming/videos/{video_id}/upload \
--header 'Authorization: <api-key>'const options = {method: 'GET', headers: {Authorization: '<api-key>'}};
fetch('https://api.gcore.com/streaming/videos/{video_id}/upload', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gcore.com/streaming/videos/{video_id}/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.get("https://api.gcore.com/streaming/videos/{video_id}/upload")
.header("Authorization", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gcore.com/streaming/videos/{video_id}/upload")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"servers": [
{
"id": 15,
"hostname": "example.com"
}
],
"token": "X2lkIjoxMDE1fSwi",
"video": {
"id": 17,
"name": "Video",
"description": "Conference July",
"client_id": 100,
"duration": 4120,
"slug": "zInSg1FL80",
"origin_size": 2974741,
"origin_host": "origin.host.org",
"origin_resource": "",
"origin_height": 1080,
"screenshots": [
"https://screenshot1.example.com/494.jpg"
],
"screenshot_id": 0,
"ad_id": 2,
"projection": "regular",
"client_user_id": 10,
"hls_url": "https://example.com/master.m3u8"
}
}Authorizations
API key for authentication. Make sure to include the word apikey, followed by a single space and then your token.
Example: apikey 1234_abcdef
Path Parameters
Video ID.
IDs of all created videos can be received via Get All Videos request
Response
Successful
An array which contains information about servers you can upload a video to.
Server; type — object.
Server has the following fields:
-
id; type — integer
Server ID -
hostname; type — string
Server hostname
Token
Contains information about the created video. See the full description in the Get video request
Was this page helpful?