This page provides instructions for uploading video files to DynTube via the API.
API URL
Please note that the API URL for video uploads is upload.dyntube.com and not api.dyntube.com.
Upload Videos 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.
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.
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;
}
}
}
}