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.
<?phpclassFileUploader {private $bearerToken;private $remoteServerUrl;publicfunction__construct($bearerToken, $remoteServerUrl) {$this->bearerToken = $bearerToken;$this->remoteServerUrl = $remoteServerUrl; }publicfunctionuploadFile($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'=>newCURLFile($filePath) );// Set the CURL optionscurl_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";returntrue; } else {echo"File upload failed. Status code: ". $statusCode ."\n";returnfalse; } }}
Python
import requestsclassFileUploader:def__init__(self,bearer_token,remote_server_url): self.bearer_token = bearer_token self.remote_server_url = remote_server_urldefupload_file(self,file_path):withopen(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 responseif response.status_code ==200:print(f"File {file_path} uploaded successfully.")returnTrueelse:print(f"File upload failed. Status code: {response.status_code}")returnFalse