Links

Upload Video

API URL

Please note that the API URL for video uploads is upload.dyntube.com and not api.dyntube.com.

Upload a Video using HTML From

  • The file can be added to form into an input named "file".
  • The Content-Type should be multipart/form-data.
  • You can optionally provide other fields, such as projectId and planType.
post
https://upload.dyntube.com/v1/
videos
Upload by file

Upload a File By URL

If you have a remote URL of a file, you can provide the URL to upload your video to DynTube.
  • The process is the same as uploading a normal file but instead of providing a file input, you can provide a field named url
  • An HTML Form should be posted to the following endpoint.
  • The Content-Type should be multipart/form-data.
  • You can optionally provide other fields, such as projectId and planType.

Code Example:

using System;
using System.Net.Http;
using System.Text;
using System.Net.Http.Headers;
using System.Collections.Generic;
namespace CallRestApi
{
class Program
{
static async System.Threading.Tasks.Task Main(string[] args)
{
using (var client = new HttpClient())
{
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("url", "your-video-url")
});
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "your-bearer-token");
var response = await client.PostAsync("https://upload.dyntube.com/v1/videos", content);
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
}
}

Replace an Existing Video

Please have a look at the optional parameters of the above two upload methods. You just need to add a parameter videoId in your upload API call to replace an existing video.

Code Examples of file uploads

C# Example

using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
public class FileUploader
{
private readonly string _bearerToken;
private readonly string _remoteServerUrl;
public FileUploader(string bearerToken, string remoteServerUrl)
{
_bearerToken = bearerToken;
_remoteServerUrl = remoteServerUrl;
}
public async Task<bool> UploadFile(string filePath)
{
using (var client = new HttpClient())
{
// Add the bearer token to the request headers
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", _bearerToken);
// Create the form data
var form = new MultipartFormDataContent();
var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath));
fileContent.Headers.ContentDisposition =
new ContentDispositionHeaderValue("form-data")
{
Name = "file",
FileName = Path.GetFileName(filePath)
};
form.Add(fileContent);
// Send the request
var response = await client.PostAsync(_remoteServerUrl, form);
// Check the status code of the response
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"File {Path.GetFileName(filePath)} uploaded successfully.");
return true;
}
else
{
Console.WriteLine($"File upload failed. Status code: {response.StatusCode}");
return false;
}
}
}
}

Node.js

const fs = require('fs');
const request = require('request');
// File to upload
const filePath = 'path/to/file.txt';
const fileName = 'file.txt';
// Remote server URL
const url = 'https://upload.dyntube.com/v1/videos';
// Bearer token for authentication
const bearerToken = 'YOUR_BEARER_TOKEN';
// Read the file data
const fileData = fs.createReadStream(filePath);
// Create the request options
const options = {
method: 'POST',
url: url,
headers: {
'Authorization': `Bearer ${bearerToken}`,
'Content-Type': 'multipart/form-data'
},
formData: {
file: fileData,
name: fileName
}
};
// Send the request
request(options, (error, response, body) => {
if (error) {
console.error(`File upload failed: ${error}`);
} else if (response.statusCode === 200) {
console.log(`File ${fileName} uploaded successfully.`);
} else {
console.error(`File upload failed. Status code: ${response.statusCode}`);
}
});

PHP

<?php
// File to upload
$filePath = 'path/to/file.txt';
$fileName = 'file.txt';
// Remote server URL
$url = 'https://upload.dyntube.com/v1/videos';
// Bearer token for authentication
$bearerToken = 'YOUR_BEARER_TOKEN';
// Read the file data
$fileData = file_get_contents($filePath);
// Create the request headers
$headers = [
'Authorization: Bearer ' . $bearerToken,
'Content-Type: multipart/form-data'
];
// Create the POST data
$postData = [
'file' => $fileData,
'name' => $fileName
];
// Create the cURL request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Send the request
$response = curl_exec($ch);
// Close the request
curl_close($ch);
// Check the status code of the response
$statusCode = http_response_code();
if ($statusCode == 200) {
echo "File $fileName uploaded successfully.";
} else {
echo "File upload failed. Status code: $statusCode";
}

Python

import requests
# File to upload
file_path = 'path/to/file.txt'
file_name = 'file.txt'
# Remote server URL
url = 'https://upload.dyntube.com/v1/videos'
# Bearer token for authentication
bearer_token = 'YOUR_BEARER_TOKEN'
# Read the file data
file_data = open(file_path, 'rb')
# Create the request headers
headers = {
'Authorization': 'Bearer ' + bearer_token,
'Content-Type': 'multipart/form-data'
}
# Create the POST data
post_data = {
'file': file_data,
'name': file_name
}
# Send the request
response = requests.post(url, headers=headers, data=post_data)
# Close the file
file_data.close()
# Check the status code of the response
if response.status_code == 200:
print(f"File {file_name} uploaded successfully.")
else:
print(f"File upload failed. Status code: {response.status_code}")

Go

package main
import (
"bytes"
"mime/multipart"
"net/http"
"os"
)
func main() {
// File to upload
filePath := "path/to/file.txt"
fileName := "file.txt"
// Remote server URL
url := "https://upload.dyntube.com/v1/videos"
// Bearer token for authentication
bearerToken := "YOUR_BEARER_TOKEN"
// Create the POST data
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("file", fileName)
if err != nil {
println(err)
return
}
file, err := os.Open(filePath)
if err != nil {
println(err)
return
}
defer file.Close()
_, err = io.Copy(part, file)
if err != nil {
println(err)
return
}
// Close the multipart writer
err = writer.Close()
if err != nil {
println(err)
return
}
// Create the request
req, err := http.NewRequest("POST", url, body)
if err != nil {
println(err)
return
}
// Add headers
req.Header.Add("Content-Type", writer.FormDataContentType())
req.Header.Add("Authorization", "Bearer "+bearerToken)
// Send the request
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
println(err)
return
}
defer res.Body.Close()
// Check the status code of the response
if res.StatusCode == 200 {
println("File " + fileName + " uploaded successfully.")
} else {
println("File upload failed. Status code: " + res.Status)
}
}