> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# छवि या वीडियो अपलोड करें

> अपनी पोस्ट में शामिल करने के लिए एक छवि या छोटी वीडियो फ़ाइल अपलोड करें

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

यह endpoint आपको अपनी पोस्ट में शामिल करने के लिए एक फ़ाइल या एक छवि या छोटी वीडियो अपलोड करने की अनुमति देता है। लौटाया गया छवि का URL होगा जिसका उपयोग /post endpoint में किया जा सकता है।

आप फ़ाइल को या तो ***multipart form data*** के रूप में एक form पैरामीटर के रूप में या **Base64 encoded file** के रूप में एक body पैरामीटर के रूप में पास कर सकते हैं।

मीडिया अपलोड के बारे में महत्वपूर्ण नोट्स:

1. सर्वोत्तम प्रदर्शन के लिए, हम अनुशंसा करते हैं
   <ul className="custom-bullets">
     <li>अपने स्वयं के सर्वर पर मीडिया फ़ाइलें होस्ट करना (उदा. AWS S3)।</li>
     <li>मीडिया URL को सीधे [/post](/apis/post/overview) endpoint के `mediaUrls` पैरामीटर में पास करना।</li>
     <li>यह दृष्टिकोण इस endpoint के माध्यम से फ़ाइलें अपलोड करने से तेज़ है।</li>
   </ul>

2. मीडिया फ़ाइल प्रतिधारण

   <ul className="custom-bullets">
     <li>अपलोड की गई फ़ाइलें 90 दिनों तक संग्रहीत की जाती हैं।</li>
     <li>90 दिनों के बाद:</li>

     <ul className="custom-bullets">
       <li>सोशल नेटवर्क पर प्रकाशित पोस्ट अप्रभावित रहती हैं।</li>
       <li>यदि shed पोस्ट्स समाप्त हो चुके मीडिया का संदर्भ देती हैं तो वे प्रकाशित होने में विफल हो जाएँगी।</li>
     </ul>
   </ul>

3. फ़ाइल आकार सीमाएँ
   <ul className="custom-bullets">
     <li>अधिकतम फ़ाइल आकार: 30 MB.</li>
     <li>बड़ी फ़ाइलों के लिए, [handling large media uploads](/apis/media/upload-large-media) पर हमारा गाइड देखें।</li>
   </ul>

<Tip>यदि आपका मीडिया पहले से ही किसी बाहरी URL, जैसे S3 bucket, द्वारा एक्सेस करने योग्य है, तो आप Ayrshare पर फ़ाइलें अपलोड करना छोड़ सकते हैं। बस `mediaURLs` body पैरामीटर में अपने बाहरी रूप से एक्सेस करने योग्य URL के साथ `/post` endpoint पर POST करें और आपकी फ़ाइल अपने आप अपलोड हो जाएगी।</Tip>

## Header Parameters

<HeaderAPI noProfileKey={true} />

<ParamField body="Content-Type" type="string" required>
  यदि आप एक multipart form data भेज रहे हैं तो `multipart/form-data` का उपयोग करें - नीचे देखें। अन्यथा, मानक `application/json` भेजें।
</ParamField>

## Body Parameters

<ParamField body="file" type="string or object" required>
  अधिकतम 30 MB फ़ाइल आकार।

  हम Base64 encoding के बजाय multipart form-data ऑब्जेक्ट के रूप में भेजने की अनुशंसा करते हैं।
</ParamField>

<ParamField body="fileName" type="string">
  अपलोड की जाने वाली फ़ाइल का नाम।
</ParamField>

<ParamField body="description" type="string">
  फ़ाइल का विवरण।
</ParamField>

### Multipart Form-Data के रूप में भेजें

मीडिया फ़ाइल को multipart form-data ऑब्जेक्ट के रूप में भेजें। कृपया ऊपर बताए अनुसार `Content-Type` निर्दिष्ट करना सुनिश्चित करें।

### Base64 के रूप में भेजें

मीडिया फ़ाइल को Data URI string के रूप में एक Base64 encoded string के रूप में भेजें। string को `data:content/type;base64` से शुरू होना चाहिए।

Output Format Data URI के साथ encoding का उदाहरण:

<ul className="custom-bullets">
  <li>Image: [https://base64.guru/converter/encode/image](https://base64.guru/converter/encode/image)</li>
  <li>Video: [https://base64.guru/converter/encode/video](https://base64.guru/converter/encode/video)</li>
</ul>

नोट: /post endpoint `mediaUrls` पैरामीटर के साथ एक बाहरी URL के माध्यम से बड़ी फ़ाइलें स्वीकार करता है।

<RequestExample>
  ```bash cURL theme={"system"}
  # Send as Multipart Form-Data
  curl \
  -H "Authorization: Bearer API_KEY" \
  -F "file=@test.png" \
  -F "fileName=test.png" \
  -F "description=best image" \
  -X POST https://api.ayrshare.com/api/media/upload

  # Send as Base64
  curl \
  -H "Authorization: Bearer API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"file": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...", "fileName": "test.png", "description": "best image"}' \
  -X POST https://api.ayrshare.com/api/media/upload
  ```

  ```javascript JavaScript theme={"system"}
  // Send as Multipart Form-Data
  const FormData = require('form-data');
  const fs = require('fs');

  const API_KEY = "API_KEY";
  const imagePath = './test.png';

  const form = new FormData();
  form.append('file', fs.createReadStream(imagePath));
  form.append('fileName', 'test.png');
  form.append('description', 'best image');

  fetch("https://api.ayrshare.com/api/media/upload", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${API_KEY}`
      // Don't set Content-Type header - FormData will set it automatically with boundary
    },
    body: form
  })
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(console.error);

  // Send as Base64
  const API_KEY = "API_KEY";
  const base64 = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...";

  fetch("https://api.ayrshare.com/api/media/upload", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${API_KEY}`
        },
        body: JSON.stringify({
          file: base64,
          fileName: "test.png",
          description: "best image"
        }),
      })
        .then((res) => res.json())
        .then((json) => console.log(json))
        .catch(console.error);
  ```

  ```python Python theme={"system"}
  # Send as Multipart Form-Data
  import requests

  # For a local file:
  files = {
      'file': ('test.png', open('test.png', 'rb')),
  }

  # Form data
  data = {
      'fileName': 'test.png',
      'description': 'best image'
  }
  headers = {
      'Authorization': 'Bearer API_KEY'
  }

  r = requests.post(
      'https://api.ayrshare.com/api/media/upload',
      files=files,
      data=data,
      headers=headers
  )

  print(r.json())

  # Send as Base64
  import requests

  payload = {'file': 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...',
          'fileName': "test.png",
          'description': "best image"}
  headers = {'Content-Type': 'application/json',
          'Authorization': 'Bearer API_KEY'}

  r = requests.post('https://api.ayrshare.com/api/media/upload',
      json=payload,
      headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  # Send as Multipart Form-Data
  <?php
    // Generate a boundary string
    $boundary = uniqid();

    // Open the file
    $file = file_get_contents('test.png');

    // Build the multipart form data
    $data = '';
    $data .= "--" . $boundary . "\r\n";
    $data .= 'Content-Disposition: form-data; name="file"; filename="test.png"' . "\r\n";
    $data .= "Content-Type: image/png\r\n\r\n";
    $data .= $file . "\r\n";

    $data .= "--" . $boundary . "\r\n";
    $data .= 'Content-Disposition: form-data; name="fileName"' . "\r\n\r\n";
    $data .= "test.png\r\n";

    $data .= "--" . $boundary . "\r\n";
    $data .= 'Content-Disposition: form-data; name="description"' . "\r\n\r\n";
    $data .= "best image\r\n";

    $data .= "--" . $boundary . "--\r\n";

    // Setup the context for the request
    $options = [
        'http' => [
            'method' => 'POST',
            'header' => "Authorization: Bearer API_KEY\r\n" .
                      "Content-Type: multipart/form-data; boundary=" . $boundary . "\r\n" .
                      "Content-Length: " . strlen($data) . "\r\n",
            'content' => $data
        ]
    ];

    // Send the request
    $context = stream_context_create($options);
    $result = file_get_contents('https://api.ayrshare.com/api/media/upload', false, $context);

    // Print the response
    echo $result;

  # Send as Base64
  <?php
  $data = [
      'file' => 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...',
      'fileName' => "test.png",
      'description' => "best image"
  ];

  $ch = curl_init('https://api.ayrshare.com/api/media/upload');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Content-Type: application/json',
      'Authorization: Bearer API_KEY'
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  echo json_encode(json_decode($response), JSON_PRETTY_PRINT);
  ```
</RequestExample>

<ResponseExample>
  ```javascript 200: Success theme={"system"}
  {
      "id": "1167335b-6c37-4fc6-ab8a-044e0005d335-jpeg",
      "url": "https://images.ayrshare.com/q3Ls85VTsrbODnGIJHpy7PaHWwA3/1167335b-6c37-4fc6-ab8a-044ed885d.jpeg",
      "fileName": "fun.jpg",
      "description": "good times"
  }
  ```

  ```json 400: Bad Request Error in upload theme={"system"}
  {
    "action": "request",
    "status": "error",
    "code": 101,
    "message": "Missing or incorrect parameters. Please verify with the docs. .../ayrshare.com/rest-api/endpoints"
  }
  ```
</ResponseExample>
