# Downloading Media from OnlyFans CDN (/introduction/guides/downloading-media)



OnlyFans API makes it easy to download media files directly from OnlyFans CDN URLs. You can download photos, videos, and audio files by calling our download endpoint with the CDN URL.

## Download media from OnlyFans CDN

<Callout>
  The full media download endpoint documentation can be found
  [here](/api-reference/media/download-media-from-the-only-fans-cdn).
</Callout>

Media can be downloaded by calling GET `https://app.onlyfansapi.com/api/{account}/media/download/{ONLYFANS_CDN_URL}`.

The `{ONLYFANS_CDN_URL}` parameter should be a URL from OnlyFans CDN (e.g., `https://cdn2.onlyfans.com/files/e/e5/123/600x400_123.jpg?Tag=2&u=123&Policy=123&Signature=signature&Key-Pair-Id=123`). You can just enter the OnlyFans CDN URL after the `.../media/download/{ONLYFANS_CDN_URL}` without any need for encoding the URL.

<CodeBlockTabs defaultValue="cURL">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="cURL">
      cURL
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="JavaScript (Fetch)">
      JavaScript (Fetch)
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="Node.js (Axios)">
      Node.js (Axios)
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="PHP (Guzzle)">
      PHP (Guzzle)
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="cURL">
    ```bash
    curl --location 'https://app.onlyfansapi.com/api/{account}/media/download/https://cdn2.onlyfans.com/files/e/e5/123/600x400_123.jpg?Tag=2&u=123&Policy=123&Signature=signature&Key-Pair-Id=123' \
         --header 'Authorization: Bearer {token}' \
         --output 'downloaded-media.jpg'
    ```
  </CodeBlockTab>

  <CodeBlockTab value="JavaScript (Fetch)">
    ```ts
    const myHeaders = new Headers();
    myHeaders.append("Authorization", "Bearer {token}");

    const cdnUrl =
      "https://cdn2.onlyfans.com/files/e/e5/123/600x400_123.jpg?Tag=2&u=123&Policy=123&Signature=signature&Key-Pair-Id=123";

    const requestOptions = {
      method: "GET",
      headers: myHeaders,
    };

    fetch(
      `https://app.onlyfansapi.com/api/{account}/media/download/${cdnUrl}`,
      requestOptions
    )
      .then((response) => response.blob())
      .then((blob) => {
        // Save the blob to a file or process it
        const url = window.URL.createObjectURL(blob);
        const a = document.createElement("a");
        a.href = url;
        a.download = "downloaded-media.jpg";
        a.click();
      })
      .catch((error) => console.error(error));
    ```
  </CodeBlockTab>

  <CodeBlockTab value="Node.js (Axios)">
    ```js
    const axios = require("axios");
    const fs = require("fs");

    const cdnUrl =
      "https://cdn2.onlyfans.com/files/e/e5/123/600x400_123.jpg?Tag=2&u=123&Policy=123&Signature=signature&Key-Pair-Id=123";

    let config = {
      method: "get",
      url: `https://app.onlyfansapi.com/api/{account}/media/download/${cdnUrl}`,
      headers: {
        Authorization: "Bearer {token}",
      },
      responseType: "stream",
    };

    axios
      .request(config)
      .then((response) => {
        response.data.pipe(fs.createWriteStream("downloaded-media.jpg"));
      })
      .catch((error) => {
        console.log(error);
      });
    ```
  </CodeBlockTab>

  <CodeBlockTab value="PHP (Guzzle)">
    ```php
    $client = new Client();

    $headers = [
        'Authorization' => 'Bearer {token}'
    ];

    $cdnUrl = "https://cdn2.onlyfans.com/files/e/e5/123/600x400_123.jpg?Tag=2&u=123&Policy=123&Signature=signature&Key-Pair-Id=123";

    $request = new Request('GET', "https://app.onlyfansapi.com/api/{account}/media/download/{$cdnUrl}", $headers);

    $res = $client->sendAsync($request)->wait();

    file_put_contents('downloaded-media.jpg', $res->getBody());
    ```
  </CodeBlockTab>
</CodeBlockTabs>

The endpoint will return the media file directly, which you can then save to your local storage or process as needed.
