curl --request POST \
--url https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"domain": "courses.example.com",
"maxSizeBytes": 2147483648,
"title": "Lesson 1 - Introduction",
"expiresInSeconds": 3600
}
'import requests
url = "https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens"
payload = {
"domain": "courses.example.com",
"maxSizeBytes": 2147483648,
"title": "Lesson 1 - Introduction",
"expiresInSeconds": 3600
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
domain: 'courses.example.com',
maxSizeBytes: 2147483648,
title: 'Lesson 1 - Introduction',
expiresInSeconds: 3600
})
};
fetch('https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens', 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.segmnt.cloud/v1/projects/{projectId}/upload-tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'domain' => 'courses.example.com',
'maxSizeBytes' => 2147483648,
'title' => 'Lesson 1 - Introduction',
'expiresInSeconds' => 3600
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens"
payload := strings.NewReader("{\n \"domain\": \"courses.example.com\",\n \"maxSizeBytes\": 2147483648,\n \"title\": \"Lesson 1 - Introduction\",\n \"expiresInSeconds\": 3600\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"domain\": \"courses.example.com\",\n \"maxSizeBytes\": 2147483648,\n \"title\": \"Lesson 1 - Introduction\",\n \"expiresInSeconds\": 3600\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"domain\": \"courses.example.com\",\n \"maxSizeBytes\": 2147483648,\n \"title\": \"Lesson 1 - Introduction\",\n \"expiresInSeconds\": 3600\n}"
response = http.request(request)
puts response.read_body{
"token": "<string>",
"expiresAt": "2023-11-07T05:31:56Z",
"projectId": "prj_2bN6rD",
"domain": "courses.example.com",
"maxSizeBytes": 123,
"contentTypes": [
"<string>"
],
"title": "Lesson 1 - Introduction"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}Create a browser upload token
Call this from your server when a user uploads a file from the browser. The token is short-lived and single-use: it allows exactly two calls, one create and the matching complete, and nothing else. It cannot read, list, delete or play.
The key stays on your server. Send the returned token to the browser,
which calls the upload routes with Authorization: Bearer <token> and
the Origin of the verified domain.
The token carries a maximum size and the allowed content type, and we enforce both. It is also bound to one verified domain of the project: a browser on any other domain is refused. Origin is not a substitute for the token, so a leaked token is limited by its size cap, one-shot use and short life.
Requires a full-scope project API key.
curl --request POST \
--url https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"domain": "courses.example.com",
"maxSizeBytes": 2147483648,
"title": "Lesson 1 - Introduction",
"expiresInSeconds": 3600
}
'import requests
url = "https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens"
payload = {
"domain": "courses.example.com",
"maxSizeBytes": 2147483648,
"title": "Lesson 1 - Introduction",
"expiresInSeconds": 3600
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
domain: 'courses.example.com',
maxSizeBytes: 2147483648,
title: 'Lesson 1 - Introduction',
expiresInSeconds: 3600
})
};
fetch('https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens', 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.segmnt.cloud/v1/projects/{projectId}/upload-tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'domain' => 'courses.example.com',
'maxSizeBytes' => 2147483648,
'title' => 'Lesson 1 - Introduction',
'expiresInSeconds' => 3600
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens"
payload := strings.NewReader("{\n \"domain\": \"courses.example.com\",\n \"maxSizeBytes\": 2147483648,\n \"title\": \"Lesson 1 - Introduction\",\n \"expiresInSeconds\": 3600\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"domain\": \"courses.example.com\",\n \"maxSizeBytes\": 2147483648,\n \"title\": \"Lesson 1 - Introduction\",\n \"expiresInSeconds\": 3600\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.segmnt.cloud/v1/projects/{projectId}/upload-tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"domain\": \"courses.example.com\",\n \"maxSizeBytes\": 2147483648,\n \"title\": \"Lesson 1 - Introduction\",\n \"expiresInSeconds\": 3600\n}"
response = http.request(request)
puts response.read_body{
"token": "<string>",
"expiresAt": "2023-11-07T05:31:56Z",
"projectId": "prj_2bN6rD",
"domain": "courses.example.com",
"maxSizeBytes": 123,
"contentTypes": [
"<string>"
],
"title": "Lesson 1 - Introduction"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>"
}Authorizations
Project API key. Server-side only.
Path Parameters
^prj_[A-Za-z0-9]+$Body
A verified domain of the project, where the browser runs.
"courses.example.com"
Hard cap on the uploaded file size, in bytes. Defaults to the plan maximum and is never allowed above it.
x >= 12147483648
The one content type the upload may declare. Omit it to allow any supported type.
video/mp4, video/quicktime, video/webm, video/x-matroska 1 - 200"Lesson 1 - Introduction"
How long the token lives. Keep it short; it is single-use.
300 <= x <= 7200Response
Token created.
Opaque signed token. Send it to the browser, which uses it as
Authorization: Bearer <token>. Never send your API key to a
browser. Do not log the token.
The project the token may upload to.
"prj_2bN6rD"
The verified domain the token is bound to.
"courses.example.com"
Hard cap on the uploaded file size, in bytes.
The content types the upload may declare.
1 - 200"Lesson 1 - Introduction"