Video Upload via File (Server Side)

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.

API Request

POST https://upload.dyntube.com/v1/videos

Request Body

Name
Type
Description

projectId

String

Project Id

planType

Integer

file*

File

File to upload

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.

Response

{
    "videoKey": "hgor6PnFQ",
    "uploadId": "3060c035-95ec-76495564",
    "videoId": "DTQ5It1KwNg",
    "channelKey": "u3u0iNPlL1Bg",
    "privateLink": "pheF3ukFQQ",
    "iframeLink": "klGiWrxW0nPzxw"
}

Code examples for uploading videos via file input

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 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;
            }
        }
    }
}

Node.js

import { createReadStream } from 'fs';
import { FormData } from 'formdata-node';
import fetch from 'node-fetch';

const bearerToken = 'your-bearer-token-here';
const filePath = './path-to-your-file.mp4';
const remoteServerUrl = 'https://upload.dyntube.com/v1/videos';

const uploadFile = async () => {
    const form = new FormData();
    form.append('file', createReadStream(filePath));

    try {
        const response = await fetch(remoteServerUrl, {
            method: 'POST',
            headers: { 'Authorization': `Bearer ${bearerToken}` },
            body: form
        });

        const result = await response.text();
        console.log('Upload successful:', result);
    } catch (error) {
        console.error('Upload failed:', error);
    }
};

uploadFile();

PHP

<?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;
        }
    }
}

Python

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 updated