How to upload videos using API

Please make sure that you are already familiar with our API and you have read our How to get started guide.

Here is the link to our upload API docs.

https://app.swaggerhub.com/apis-docs/dyntube.com/upload/v1

To upload videos using API. Please use the following URL and make a HTTTP POST request.

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



#The Content-Type should be multipart/form-data.

"projectId": "1lXvAX6Dk235fsd65GGRUcCw",
"file": [file-contents]


Once a HTTP POST request is made successfullly, the response will return JSON with the video Id and video Key.


{
    "videoKey": "1lXvAX6Dk235fsd65GGRUcCw",
    "uploadId": "7a554808-822a-49bf-93fb-067c44245503",
    "videoId": "3dfdfisqIh125459gApj1g"
}

Upload Videos using Links

If your videos are not available on your local file system, you can upload videos to DynTube using remote URLs. In order to upload a video using a URL, you need a URL that resolves directly to a video file. In your HTML form, there should be the field named "url" and the value of the field should be the URL of the video file.

    

        #The Content-Type should be multipart/form-data.
        "url": http://techslides.com/demos/sample-videos/small.mp4

    

Here are some code examples

Remember to replace {{projectId}} and {{token}} with actual values.

cURL


        curl --location --request POST 'https://upload.dyntube.com/v1/videos' \
        --header 'Authorization: Bearer {{token}}' \
        --form 'projectId="{{projectId}}"' \
        --form 'file=@"/path/to/file"'

    
C# - using RestSharp Library

        var client = new RestClient("https://upload.dyntube.com/v1/videos");
        client.Timeout = -1;
        var request = new RestRequest(Method.POST);
        request.AddHeader("Authorization", "Bearer {{token}}");
        request.AddParameter("projectId", "{{projectId}}");
        request.AddFile("file", "/path/to/file");
        IRestResponse response = client.Execute(request);
        Console.WriteLine(response.Content);


    
NodeJs - using Axios


        var axios = require('axios');
        var FormData = require('form-data');
        var fs = require('fs');
        var data = new FormData();
        data.append('projectId', '{{projectId}}');
        data.append('file', fs.createReadStream('/path/to/file'));

        var config = {
        method: 'post',
        url: 'https://upload.dyntube.com/v1/videos',
        headers: {
        'Authorization': 'Bearer {{token}}',
        ...data.getHeaders()
        },
        data : data
        };

        axios(config)
        .then(function (response) {
        console.log(JSON.stringify(response.data));
        })
        .catch(function (error) {
        console.log(error);
        });



    
PHP - cURL File upload




        <?php

        if (isset($_POST['btnUpload']))
        {
        $message='';

        $url = "https://upload.dyntube.com/v1/videos";
        $filename = $_FILES['file']['name'];
        $filedata = $_FILES['file']['tmp_name'];
        $filesize = $_FILES['file']['size'];
        $filetype = $_FILES['file']['type'];

        if ($filedata != '')
        {
        $headers = array(
        'Content-type: multipart/form-data',
        'Authorization: Bearer {{token}}',
        );


        $postfields = array("projectId" => "{{projectId}}",'file' => new CURLFile(realpath($filedata),$filetype,$filename));

        $ch = curl_init();
        $options = array(
        CURLOPT_URL => $url,
        CURLOPT_HEADER => true,
        CURLOPT_POST => 1,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_POSTFIELDS => $postfields,
        CURLOPT_INFILESIZE => $filesize,
        CURLOPT_RETURNTRANSFER => true
        ); // cURL options
        curl_setopt_array($ch, $options);
        $message= curl_exec($ch);
        if(!curl_errno($ch))
        {
        $info = curl_getinfo($ch);
        if ($info['http_code'] == 200)
        $message = "File uploaded successfully";
        }
        else
        {
        $message = curl_error($ch);
        }
        curl_close($ch);
        }
        else
        {
        $message = "Please select the file";
        }

        echo $message;
        }

        ?>

        <form method="post" enctype="multipart/form-data">
        <input type="file" name="file" id="file" />

        <br /><br />

        <input type="submit" name="btnUpload" value="Submit" />



    
PHP - HTTP_Request2



        setUrl('https://upload.dyntube.com/v1/videos');
        $request->setMethod(HTTP_Request2::METHOD_POST);
        $request->setConfig(array(
        'follow_redirects' => TRUE
        ));
        $request->setHeader(array(
        'Authorization' => 'Bearer {{token}}'
        ));
        $request->addPostParameter(array(
        'projectId' => '{{projectId}}'
        ));
        $request->addUpload('file', '/path/to/file', '/path/to/file', '
            ');
            try {
            $response = $request->send();
            if ($response->getStatus() == 200) {
            echo $response->getBody();
            }
            else {
            echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
            $response->getReasonPhrase();
            }
            }
            catch(HTTP_Request2_Exception $e) {
            echo 'Error: ' . $e->getMessage();
            }

    
Python - Requests


        import requests

        url = "https://upload.dyntube.com/v1/videos"

        payload={'projectId': '{{projectId}}'}
        files=[
        ('file',('file',open('/path/to/file','rb'),'application/octet-stream'))
        ]
        headers = {
        'Authorization': 'Bearer {{token}}'
        }

        response = requests.request("POST", url, headers=headers, data=payload, files=files)

        print(response.text)



    
Ruby - Net::HTTP


        require "uri"
        require "net/http"

        url = URI("https://upload.dyntube.com/v1/videos")

        https = Net::HTTP.new(url.host, url.port)
        https.use_ssl = true

        request = Net::HTTP::Post.new(url)
        request["Authorization"] = "Bearer {{token}}"
        form_data = [['projectId', '{{projectId}}'],['file', File.open('/path/to/file')]]
        request.set_form form_data, 'multipart/form-data'
        response = https.request(request)
        puts response.read_body


    
Java - Unirest


        Unirest.setTimeouts(0, 0);
        HttpResponse
            response = Unirest.post("https://upload.dyntube.com/v1/videos")
            .header("Authorization", "Bearer {{token}}")
            .field("projectId", "{{projectId}}")
            .field("file", new File("/path/to/file"))
            .asString();


    
Dart - http


        var headers = {
        'Authorization': 'Bearer {{token}}'
        };
        var request = http.MultipartRequest('POST', Uri.parse('https://upload.dyntube.com/v1/videos'));
        request.fields.addAll({
        'projectId': '{{projectId}}'
        });
        request.files.add(await http.MultipartFile.fromPath('file', '/path/to/file'));
        request.headers.addAll(headers);

        http.StreamedResponse response = await request.send();

        if (response.statusCode == 200) {
        print(await response.stream.bytesToString());
        }
        else {
        print(response.reasonPhrase);
        }