Upload Videos (Server Side)
Please note that the API URL for video uploads is
upload.dyntube.com
and not api.dyntube.com
.- 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
andplanType.
post
https://upload.dyntube.com/v1/
videos
Upload by file
Parameters
Body
file*
File
File to upload
projectId
String
Project Id
title
String
Video Title
videoId
String
To replace an existing video
description
String
Video description
tags
String
Video tags, add multiple tags by adding the 'tags' field multiple times in your POST request with different values.
Responses
200: OK
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
andplanType.
post
https://upload.dyntube.com/v1/
videos
Upload by link
Parameters
Body
url*
String
URL where the video is stored. This URL should directly return the video and it should not be redirected to somewhere else.
projectId
String
Project Id
videoId
String
To replace an existing video
Responses
200: OK
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);
}
}
}
}
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.
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 StreamContent(File.OpenRead(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;
}
}
}
}
const fs = require('fs');
const fetch = require('node-fetch');
class FileUploader {
constructor(bearerToken, remoteServerUrl) {
this.bearerToken = bearerToken;
this.remoteServerUrl = remoteServerUrl;
}
async uploadFile(filePath) {
const form = new FormData();
form.append('file', fs.createReadStream(filePath));
const response = await fetch(this.remoteServerUrl, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + this.bearerToken
},
body: form
});
if (response.ok) {
console.log(`File ${filePath} uploaded successfully.`);
return true;
} else {
console.log(`File upload failed. Status code: ${response.status}`);
return false;
}
}
}
module.exports = FileUploader;
<?php
class FileUploader {
private $bearerToken;
private $remoteServerUrl;
public function __construct($bearerToken, $remoteServerUrl) {
$this->bearerToken = $bearerToken;
$this->remoteServerUrl = $remoteServerUrl;
}
public function uploadFile($filePath) {
$curl = curl_init();
// Add the bearer token to the request headers
$headers = array(
'Authorization: Bearer ' . $this->bearerToken
);
// Create the form data
$formData = array(
'file' => new CURLFile($filePath)
);
// Set the CURL options
curl_setopt($curl, CURLOPT_URL, $this->remoteServerUrl);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $formData);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Send the request
$response = curl_exec($curl);
// Check the status code of the response
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($statusCode == 200) {
echo "File " . basename($filePath) . " uploaded successfully.\n";
return true;
} else {
echo "File upload failed. Status code: " . $statusCode . "\n";
return false;
}
}
}
import requests
class FileUploader:
def __init__(self, bearer_token, remote_server_url):
self.bearer_token = bearer_token
self.remote_server_url = remote_server_url
def upload_file(self, file_path):
with open(file_path, 'rb') as f:
# Create the form data
form = {
'file': (file_path, f)
}
# Add the bearer token to the request headers
headers = {
'Authorization': 'Bearer ' + self.bearer_token
}
# Send the request
response = requests.post(self.remote_server_url, headers=headers, files=form)
# Check the status code of the response
if response.status_code == 200:
print(f"File {file_path} uploaded successfully.")
return True
else:
print(f"File upload failed. Status code: {response.status_code}")
return False
Last modified 3mo ago