> ## 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.

# बड़ी Media फ़ाइलें अपलोड करें

> 10 MB से बड़ी फ़ाइल अपलोड के लिए, फ़ाइल अपलोड करने के लिए एक presigned URL प्राप्त करें

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} />

10 MB से बड़ी फ़ाइल अपलोड के लिए, फ़ाइल अपलोड करने के लिए एक presigned URL प्राप्त करें।

<ul class="custom-bullets">
  <li>अधिकतम फ़ाइल अपलोड आकार 5 GB।</li>
  <li>Upload presigned URL generate होने के बाद 30 मिनट तक वैध।</li>

  <li>
    Access URL अपलोड होने के बाद 30 दिनों तक उपलब्ध। सभी प्रकाशित पोस्ट सोशल नेटवर्क पर अप्रभावित रहते हैं।
    उस समय सीमा से आगे के scheduled पोस्ट प्रकाशन के समय errors का कारण बनेंगे।
  </li>
</ul>

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

## Header Parameters

<HeaderAPI noProfileKey={true} />

## Query Parameters

<ParamField query="fileName" type="string">
  यदि contentType मौजूद नहीं है, तो extension के साथ एक पूर्ण फ़ाइल नाम आवश्यक है।

  अपलोड की जाने वाली फ़ाइल का नाम। इसमें एक extension शामिल होना चाहिए जैसे .png, .jpg, .mov, .mp4, आदि।
</ParamField>

<ParamField query="contentType" type="string">
  अपलोड की जाने वाली media का content-type। मान्य फ़ॉर्मैट्स में शामिल हैं: `mp4`, `mov`, `png`, `jpg`, या `jpeg`।

  उदाहरण के लिए, यदि फ़ाइल एक Quicktime .mov फ़ाइल है, तो contentType `mov` होना चाहिए।

  यदि मौजूद नहीं है, तो application/octet-stream का उपयोग किया जाएगा।
</ParamField>

<RequestExample>
  ```bash cURL theme={"system"}
  curl \
  -H "Authorization: Bearer [API Key]" \
  -X GET https://api.ayrshare.com/api/media/uploadUrl?fileName=test.mov&contentType=mov
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "Your API Key";

  fetch("https://api.ayrshare.com/api/media/uploadUrl?fileName=test.mov&contentType=mov", {
        method: "GET",
        headers: {
          "Authorization": `Bearer ${API_KEY}`
        }
      })
        .then((res) => res.json())
        .then((json) => console.log(json))
        .catch(console.error);
  ```

  ```python Python theme={"system"}
  import requests

  headers = {'Authorization': 'Bearer [API_KEY]'}

  r = requests.get('https://api.ayrshare.com/api/media/uploadUrl?fileName=test.mov&contentType=mov', headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  <?php
  require 'vendor/autoload.php';    // Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html

  $client = new GuzzleHttp\Client();
  $res = $client->request(
      'GET',
      'https://api.ayrshare.com/api/media/uploadUrl?fileName=test.mov&contentType=mov',
      [
          'headers' => [
              'Content-Type'      => 'application/json',
              'Authorization'     => 'Bearer API_KEY'
          ]
      ]
  );

  echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Threading.Tasks;
  using System.Web;

  namespace MediaUploadUrlGETRequest_csharp
  {
      class MediaUploadUrl
      {
          static async Task Main(string[] args)
          {
              string API_KEY = "API_KEY";
              string baseUrl = "https://api.ayrshare.com/api/media/uploadUrl";

              // Build URL with query parameters
              var uriBuilder = new UriBuilder(baseUrl);
              var query = HttpUtility.ParseQueryString(string.Empty);
              query["fileName"] = "test.mov";
              query["contentType"] = "mov";
              uriBuilder.Query = query.ToString();

              using (var client = new HttpClient())
              {
                  client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

                  try
                  {
                      HttpResponseMessage response = await client.GetAsync(uriBuilder.Uri);
                      response.EnsureSuccessStatusCode();
                      string responseBody = await response.Content.ReadAsStringAsync();
                      Console.WriteLine(responseBody);
                  }
                  catch (HttpRequestException e)
                  {
                      Console.WriteLine($"Error: {e.Message}");
                  }
              }
          }
      }
  }
  ```
</RequestExample>

## Response विवरण

<ul class="custom-bullets">
  <li>`accessUrl` अपलोड के बाद media फ़ाइल तक पहुँचने के लिए URL है।</li>

  <li>
    `contentType` अपलोड की जाने वाली media के लिए सेट किया गया content-type है। media अपलोड करते समय *Content-Type*
    header में इसका उपयोग करें।
  </li>

  <li>`uploadUrl` media फ़ाइल को *PUT* करने के लिए उपयोग किया जाने वाला URL है। कृपया नीचे देखें।</li>
</ul>

### अतिरिक्त Endpoint उदाहरण

बड़ी फ़ाइलें अपलोड करने की प्रक्रिया:

<ul class="custom-bullets">
  <li>
    `/media/uploadUrl` endpoint के माध्यम से एक `uploadURL` और `accessURL` प्राप्त करें। कृपया ऊपर देखें।
  </li>

  <li>*PUT* के माध्यम से *Content-Type* को लौटाए गए `contentType` पर सेट करके फ़ाइल अपलोड करें।</li>
  <li>Media फ़ाइल के साथ `--upload-file` और `uploadUrl` का उपयोग करके media अपलोड करें।</li>
  <li>सफल अपलोड पर, `200` response लौटाया जाएगा।</li>

  <li>
    Media फ़ाइल अपलोड करने के बाद, `mediaUrls` body parameter में `accessUrl` के साथ `/post` endpoint पर POST करें।
  </li>

  <li>
    **Presigned upload URL पर केवल एक बार अपलोड किया जा सकता है**। यदि आपने खराब फ़ाइल भेजी है तो आपको एक नया
    upload URL बनाना होगा। यदि फ़ाइल सफलतापूर्वक अपलोड नहीं होती है तो कोई error response नहीं आएगा।
    नीचे [URL मौजूद है यह verify करना](/apis/media/verify-media-url) देखें।
  </li>
</ul>

<CodeGroup>
  ```bash cURL theme={"system"}
  curl -X PUT \
  -H 'Content-Type: video/mp4' \
  --upload-file LOCAL_FILE_PATH uploadUrl
  ```

  ```javascript JavaScript theme={"system"}
  const fs = require("fs").promises;
  const uploadFileToSignedUrl = async (signedUrl, filePath) => {
      try {
        const fileBuffer = await fs.readFile(filePath);
        const response = await fetch(signedUrl, {
          method: "PUT",
          body: fileBuffer,
          headers: {
            "Content-Type": "video/mp4"
          }
        });

        if (response.ok) {
          console.log("File upload successful:", response.status);
        } else {
          console.error("File upload failed:", response.status);
        }
      } catch (error) {
        console.error("Error uploading file:", error);
      }
  };

  // Use the signed URL generated from the previous step
  const signedUrl = "SIGNED_URL";
  const filePath = "LOCAL_FILE_PATH";

  uploadFileToSignedUrl(signedUrl, filePath);
  ```

  ```python Python theme={"system"}
  import requests

  def upload_file_to_signed_url(signed_url, file_path):
      try:
          with open(file_path, 'rb') as file:
              response = requests.put(signed_url, data=file, headers={'Content-Type': 'video/mp4'})

          if response.ok:
              print("File upload successful:", response.status_code)
          else:
              print("File upload failed:", response.status_code)
      except Exception as error:
          print("Error uploading file:", error)

  # Use the signed URL generated from the previous step
  signed_url = "SIGNED_URL"
  file_path = "LOCAL_FILE_PATH"

  upload_file_to_signed_url(signed_url, file_path)
  ```

  ```php PHP theme={"system"}
  <?php

  function uploadFileToSignedUrl($signedUrl, $filePath) {
      try {
          $fileHandle = fopen($filePath, 'rb');
          if ($fileHandle === false) {
              throw new Exception('Cannot open the file');
          }

          $ch = curl_init($signedUrl);

          curl_setopt($ch, CURLOPT_PUT, true);
          curl_setopt($ch, CURLOPT_INFILE, $fileHandle);
          curl_setopt($ch, CURLOPT_INFILESIZE, filesize($filePath));
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: video/mp4'));
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

          $response = curl_exec($ch);
          $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

          if ($httpCode == 200) {
              echo "File upload successful: " . $httpCode;
          } else {
              echo "File upload failed: " . $httpCode;
          }

          fclose($fileHandle);
          curl_close($ch);
      } catch (Exception $e) {
          echo "Error uploading file: " . $e->getMessage();
      }
  }

  // Use the signed URL generated from the previous step
  $signedUrl = "SIGNED_URL";
  $filePath = "LOCAL_FILE_PATH";

  uploadFileToSignedUrl($signedUrl, $filePath);
  ?>

  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.IO;
  using System.Threading.Tasks;

  class Program
  {
      static async Task Main(string[] args)
      {
          string signedUrl = "SIGNED_URL"; // Replace with your signed URL
          string filePath = "LOCAL_FILE_PATH"; // Replace with your file path

          try
          {
              await UploadFileToSignedUrl(signedUrl, filePath);
          }
          catch (Exception ex)
          {
              Console.WriteLine("Error uploading file: " + ex.Message);
          }
      }

      static async Task UploadFileToSignedUrl(string signedUrl, string filePath)
      {
          using (var client = new HttpClient())
          using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
          using (var content = new StreamContent(fileStream))
          {
              content.Headers.Add("Content-Type", "video/mp4");

              var response = await client.PutAsync(signedUrl, content);

              if (response.IsSuccessStatusCode)
              {
                  Console.WriteLine("File upload successful: " + response.StatusCode);
              }
              else
              {
                  Console.WriteLine("File upload failed: " + response.StatusCode);
              }
          }
      }
  }

  ```

  ```java Java theme={"system"}
  import java.net.URI;
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.http.HttpRequest.BodyPublishers;
  import java.nio.file.Path;
  import java.io.IOException;
  import java.nio.file.Files;

  public class FileUploader {

      public static void main(String[] args) {
          String signedUrl = "SIGNED_URL"; // Replace with your signed URL
          String filePath = "LOCAL_FILE_PATH"; // Replace with your file path

          try {
              uploadFileToSignedUrl(signedUrl, filePath);
          } catch (IOException | InterruptedException e) {
              System.out.println("Error uploading file: " + e.getMessage());
          }
      }

      private static void uploadFileToSignedUrl(String signedUrl, String filePath) throws IOException, InterruptedException {
          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
                  .uri(URI.create(signedUrl))
                  .header("Content-Type", "image/jpg")
                  .PUT(BodyPublishers.ofFile(Path.of(filePath)))
                  .build();

          HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

          if (response.statusCode() == 200) {
              System.out.println("File upload successful: " + response.statusCode());
          } else {
              System.out.println("File upload failed: " + response.statusCode());
          }
      }
  }

  ```
</CodeGroup>

कृपया सुनिश्चित करें कि `uploadUrl` बनाते समय सेट किया गया `contentType` फ़ाइल को PUT करते समय Content-Type और फ़ाइल प्रकार से मेल खाता है।
उदाहरण के लिए, यदि आपने `uploadUrl` बनाते समय `contentType` को "image/png" पर सेट किया है, तो सुनिश्चित करें कि `Content-Type: image/png` सेट किया गया है और अपलोड की गई फ़ाइल `.png` में समाप्त होती है।

सफल अपलोड पर, `200` response लौटाया जाएगा।

### Node.js में Upload File Binary उदाहरण

यहाँ JavaScript के साथ Node का उपयोग करके एक binary media फ़ाइल अपलोड करने का एक उदाहरण है:

```javascript theme={"system"}
const fs = require("fs");
const request = require("request");

const API_KEY = "Your API Key";
const fileName = "test.png";
const endpoint = `https://api.ayrshare.com/api/media/uploadUrl?fileName=${fileName}&contentType=png`;

const run = async () => {
  request.get(
    {
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${API_KEY}`
      },
      url: endpoint
    },
    (err, res, body) => {
      if (err) {
        return console.error(err);
      }

      const json = JSON.parse(body);
      console.log("Upload URL:", json);

      return fs.createReadStream(`./${fileName}`).pipe(
        request.put(
          json.uploadUrl,
          {
            headers: {
              "Content-Type": json.contentType
            }
          },
          (err, httpsResponse, body) => {
            if (err) {
              console.error("err", err);
            } else {
              console.log(body);
            }
          }
        )
      );
    }
  );
};

run();
```

### Postman में Binary File Upload उदाहरण

आप `uploadUrl` पर binary फ़ाइल अपलोड करने के लिए Postman का भी उपयोग कर सकते हैं।

Postman में:

1. HTTP Method `PUT` का चयन करें।
2. url field में अपना `uploadUrl` paste करें। ध्यान दें, url एक घंटे बाद समाप्त हो जाएगा और इसका उपयोग केवल एक बार किया जा सकता है। यदि आप एक कॉल करते हैं और यह विफल होती है, तो आपको `uploadUrl` को फिर से generate करना होगा।
3. *Headers* में `Content-Type` को /uploadUrl endpoint में लौटाए गए content type पर सेट करें। उदाहरण के लिए: `Content-Type: image/png`।
4. *Body -> binary* का चयन करें और अपलोड करने के लिए फ़ाइल का चयन करें।
5. **Send** दबाएँ।
6. **महत्वपूर्ण**: कोई return response नहीं आएगा, इसलिए आपको यह जाँचना चाहिए कि अपलोड सफल हुआ या नहीं, इसके लिए /uploadUrl endpoint से लौटाए गए `accessUrl` को browser में खोलें। आप [verify URL endpoint](/apis/media/verify-media-url) का भी उपयोग कर सकते हैं।

<img class="center" src="https://mintcdn.com/ayrshare-docs/Nmrhj2Gh7WSf62Bh/images/apis/validate/postman%20binary.webp?fit=max&auto=format&n=Nmrhj2Gh7WSf62Bh&q=85&s=ca3def769242814afb17a58d9268667f" alt="Postman Binary Upload" width="1536" height="189" data-path="images/apis/validate/postman binary.webp" />

<Card title="Postman Sample JSON File" icon="file" href="/files/Large Media File Upload.postman_collection.json" horizontal />

<ResponseExample>
  ```javascript 200: An upload URL and access URL theme={"system"}
  {
      "accessUrl": "https://media.ayrshare.com/Aswmfs3dIEbwLSdhTlV2/test.mp4",
      "contentType": "video/mp4",
      "uploadUrl": "https://storage.googleapis.com/..."
  }
  ```

  ```json 400: Bad Request Error getting signed URL theme={"system"}
  {
    "action": "upload",
    "status": "error",
    "code": 301,
    "message": "The provided content-type 'movd' is not recognized."
  }
  ```
</ResponseExample>
