Skip to content

Upload videos from third party applications

Daniel Neto edited this page Dec 9, 2024 · 21 revisions

Uploading Files to AVideo (AVideo) for Third-Party Apps

This tutorial provides step-by-step instructions for third-party applications to upload files to AVideo, ensuring secure authentication and detailed video metadata submission.


Obtaining the Password Hash

To interact with AVideo's API, you'll need to use an encrypted password. This is how you can obtain it:

1. Locate the Encryption Script:

Each AVideo installation comes with a script to encode passwords. It can vary, especially if the installation uses a salt for enhanced security. Typically, you would access it like so:

https://yourSite/objects/encryptPass.json.php?pass=YOUR_PASSWORD

Replace yourSite with your AVideo installation URL and YOUR_PASSWORD with the actual password you wish to encrypt.

2. Encrypt Your Password:

Navigate to the URL from step 1. This will return your encrypted password in JSON format. For example, using a browser or a tool like curl:

curl https://yourSite/objects/encryptPass.json.php?pass=123

This request returns an encrypted password that looks like this:

{"encryptedPassword":"ENCRYPTED_PASSWORD_HERE"}

Uploading the File

To upload files, use the Mobile Plugin Upload File endpoint. Here’s how:


1. Construct the Upload URL:

Your URL will include your username and the encrypted password obtained previously:

yourSite/plugin/MobileManager/upload.php?user=USERNAME&pass=ENCRYPTED_PASSWORD

Replace yourSite with your AVideo site URL, USERNAME with your actual username, and ENCRYPTED_PASSWORD with the encrypted password you received.


2. Submit the File Using curl:

Here’s an example of a curl command to upload the file:

curl -X POST \
  -F "upl=@/path/to/your/video.mp4" \
  -F "title=Your Video Title" \
  -F "description=A brief description of the video" \
  -F "categories_id=1" \
  -F "can_share=1" \
  -F "video_password=YourVideoPassword" \
  "https://yourSite/plugin/MobileManager/upload.php?user=USERNAME&pass=ENCRYPTED_PASSWORD"

Explanation of the Parameters:

  • -X POST: Specifies that the request is a POST request.
  • -F: Sends form data.
    • upl=@/path/to/your/video.mp4: Replace /path/to/your/video.mp4 with the full path to your video file.
    • title=Your Video Title: Replace Your Video Title with the desired title of the video.
    • description=A brief description of the video: Replace A brief description of the video with your video description.
    • categories_id=1: Replace 1 with the category ID for the video.
    • can_share=1: Set to 1 if the video can be shared; otherwise, omit this field or set it to 0.
    • video_password=YourVideoPassword: If the video requires a password, include it here; otherwise, omit this field.

3. Submit the File Using an HTML Form:

You can also use an HTML form to submit files and metadata. Below is a sample form:

<form enctype="multipart/form-data" method="post" action="https://yourSite/plugin/MobileManager/upload.php?user=USERNAME&pass=ENCRYPTED_PASSWORD">
    <input name="title" type="text" placeholder="Video Title" /><br>
    <input name="description" type="text" placeholder="Video Description" /><br>
    <input name="categories_id" type="text" placeholder="Category ID" /><br>
    <input name="can_share" type="checkbox" value="1" /> Can Share<br>
    <input name="video_password" type="password" placeholder="Video Password" /><br>
    <input name="upl" type="file" accept="video/*" /><br>
    <input type="submit" value="Upload Video" />
</form>

Replace https://yourSite with your AVideo site URL, USERNAME with your username, and ENCRYPTED_PASSWORD with your encrypted password.


4. Submit the File Using PHP:

Below is an example of how to upload a file using PHP:

<?php
// Configuration
$uploadUrl = "https://yourSite/plugin/MobileManager/upload.php";
$username = "USERNAME";
$encryptedPassword = "ENCRYPTED_PASSWORD";

// File and Metadata
$filePath = "/path/to/your/video.mp4"; // Full path to the video file
title = "Your Video Title";
description = "A brief description of the video";
categoriesId = 1; // Category ID
canShare = 1; // Set to 1 for sharing; 0 otherwise
videoPassword = "YourVideoPassword";

// Build the full URL with credentials
$uploadUrl .= "?user=" . urlencode($username) . "&pass=" . urlencode($encryptedPassword);

// Prepare the POST data
$postData = [
    'upl' => new CURLFile($filePath, mime_content_type($filePath), basename($filePath)),
    'title' => $title,
    'description' => $description,
    'categories_id' => $categoriesId,
    'can_share' => $canShare,
    'video_password' => $videoPassword,
];

// Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uploadUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute the request
$response = curl_exec($ch);

// Check for errors
if ($response === false) {
    die('Upload failed: ' . curl_error($ch));
}

// Close cURL
curl_close($ch);

// Output the response
echo "Server Response: " . $response;
?>

5. Video Metadata Parameters:

You can send additional metadata for the video using either GET or POST parameters:

  • title: The title of the video.
  • description: A brief description of the video.
  • categories_id: The ID for the video category.
  • can_share: Set this to 1 to allow sharing of the video.
  • video_password: If you wish to protect the video with a password.

Webhooks and Notifications

AVideo supports webhooks through the Notifications Plugin for events like new video uploads. For setup and more details, refer to the [Notifications Plugin documentation]


Important Notes on Server Configuration

Check the LimitRequestBody Configuration:

Ensure the LimitRequestBody directive in your server configuration allows uploads of large files. This directive sets the maximum size of the request body (in bytes) allowed by the server. If it is set too low, uploads will fail.

  • Default Value: The default value for LimitRequestBody is 1 GB if it is not set or is set to 0.
  • Recommended Value for AVideo: Set this directive to a minimum of 5 GB. For enhanced performance and larger uploads, consider setting it to 10 GB, as used in many high-performance servers.

To update this setting:

  1. Locate your Apache configuration file. This is typically httpd.conf or included files (e.g., /etc/apache2/apache2.conf or .htaccess).
  2. Open the file for editing. For example:
sudo nano /etc/apache2/apache2.conf
  1. Add or update the directive:
LimitRequestBody 10737418240  # 10 GB
  1. Save and exit the file (CTRL+O, then CTRL+X).

  2. Restart your Apache server to apply the changes:

sudo systemctl restart apache2

Check PHP Configuration for Uploads:

Ensure the PHP configuration allows for large file uploads. Update the following parameters in the PHP configuration file (php.ini):

  1. Open the php.ini file for editing:
sudo nano /etc/php/7.4/apache2/php.ini

Replace 7.4 with your PHP version if different.

  1. Locate and modify the following parameters:
upload_max_filesize = 5G
post_max_size = 5G
  1. Save and exit the file (CTRL+O, then CTRL+X).

  2. Restart Apache to apply the changes:

sudo systemctl restart apache2

Ensure these settings match the intended maximum upload size for your application.

Clone this wiki locally