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.
Code Examples of file uploads
C# Example
usingSystem;usingSystem.IO;usingSystem.Net.Http;usingSystem.Net.Http.Headers;usingSystem.Threading.Tasks;publicclassFileUploader{privatereadonlystring _bearerToken;privatereadonlystring _remoteServerUrl;publicFileUploader(string bearerToken,string remoteServerUrl) { _bearerToken = bearerToken; _remoteServerUrl = remoteServerUrl; }publicasyncTask<bool> UploadFile(string filePath) {using (var client =newHttpClient()) { // Add the bearer token to the request headersclient.DefaultRequestHeaders.Authorization=newAuthenticationHeaderValue("Bearer", _bearerToken); // Create the form datavar form =newMultipartFormDataContent();var fileContent =newStreamContent(File.OpenRead(filePath));fileContent.Headers.ContentDisposition=newContentDispositionHeaderValue("form-data") { Name ="file", FileName =Path.GetFileName(filePath) };form.Add(fileContent); // Send the requestvar response =awaitclient.PostAsync(_remoteServerUrl, form); // Check the status code of the responseif (response.IsSuccessStatusCode) {Console.WriteLine($"File {Path.GetFileName(filePath)} uploaded successfully.");returntrue; }else {Console.WriteLine($"File upload failed. Status code: {response.StatusCode}");returnfalse; } } }}
<?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