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

# Upload File from URL [POST]

> Downloads file from a source url and uploads it as a temporary file. Temporary files are automatically permanently removed after 1 hour.

## `POST /v1/file/upload/url`

<Note>This method do is same as /v1/file/upload/url but using post method.</Note>

## Query parameters

*No query parameters accepted.*

## Responses

| Parameter             | Type    | Description                                                                                                                  |
| --------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `url`                 | string  | Direct URL to the final PDF file stored in S3.                                                                               |
| `outputLinkValidTill` | string  | Timestamp indicating when the output link will expire                                                                        |
| `error`               | boolean | Indicates whether an error occurred (`false` means success)                                                                  |
| `status`              | string  | Status code of the request (200, 404, 500, etc.). For more information, see [Response Codes](/api-reference/response-codes). |
| `name`                | string  | Name of the output file                                                                                                      |
| `credits`             | integer | Number of credits consumed by the request                                                                                    |
| `remainingCredits`    | integer | Number of credits remaining in the account                                                                                   |
| `duration`            | integer | Time taken for the operation in milliseconds                                                                                 |

## `Example` Response

<Note>To see the main response codes, please refer to the [Response Codes](/api-reference/response-codes) page.</Note>

```json theme={null}
{
  "url": "https://pdf-temp-files.s3.amazonaws.com/1a4a92ac805c41c28ef75a24e0f35ba5/sample.pdf",
  "error": false,
  "status": 200,
  "name": "sample.pdf",
  "remainingCredits": 98145
}
```

<Note>
  **Inconsistent URL Encoding in cURL Output:** When using cURL to make API requests, the output JSON may show URL characters encoded as Unicode escape sequences. For example, the ampersand character (`&`) may appear as `\u0026` in the cURL output. This is normal JSON encoding behavior and does not affect the validity of the URL. The URL will function correctly when used, as JSON parsers automatically decode these escape sequences. If you're parsing the response programmatically, your JSON parser will handle this conversion automatically.
</Note>

## Code Samples

<Tabs>
  <Tab title="CURL">
    ```bash theme={null}
    curl --location --request POST 'https://api.pdf.co/v1/file/upload'
    --header 'x-api-key: *******************'
    --form 'file=@"/path/to/file"'
    ```
  </Tab>

  <Tab title="JavaScript/Node.js">
    ```javascript theme={null}
    var https = require("https");
    var path = require("path");

    const API_KEY = "*************************************";

    function upload(apiKey, fileName) {
      return new Promise(resolve => {
          // Prepare request to `file/upload/url` API endpoint
          let queryPath = `/v1/file/upload/url?url=${fileName}`;
          let reqOptions = {
              host: "api.pdf.co",
              path: encodeURI(queryPath),
              headers: { "x-api-key": apiKey }
          };
          // Send request
          https.get(reqOptions, (response) => {
              response.on("data", (d) => {
                  let data = JSON.parse(d);
                  if (data.status == 200) {
                      console.log("temp url: " + data.url);
                      console.log("remainingCredits: " + data.remainingCredits);
                      resolve([data.remainingCredits]);
                  }
                  else {
                      // Service reported error
                      console.log("Error");
                  }
              });
           })
           .on("error", (e) => {
                // Request error
                console.log("error: " + e);
           });
      });
    }

    let result = upload(API_KEY, "https://pdfco-test-files.s3.us-west-2.amazonaws.com/document-parser/sample-invoice.pdf");
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    # The authentication key (API Key).
    # Get your own by registering at https://app.pdf.co
    API_KEY = "*************************************"

    # Base URL for PDF.co Web API requests
    BASE_URL = "https://api.pdf.co/v1"

    fileName = "https://pdfco-test-files.s3.us-west-2.amazonaws.com/document-parser/sample-invoice.pdf"

    url = "{}/file/upload/url?url={}".format(BASE_URL, fileName)

    # Execute request and get response as JSON
    response = requests.get(url, headers={"x-api-key": API_KEY})
    if (response.status_code == 200):
        json = response.json()

        if json["status"] == 200:
            temp_url = json["url"]
            remainingCredits = json["remainingCredits"]
    ```
  </Tab>

  <Tab title="PHP">
    ```php theme={null}
    <?php
      $apiKey = "***************";
      $fileName = "https://pdfco-test-files.s3.us-west-2.amazonaws.com/document-parser/sample-invoice.pdf";
      $url = "https://api.pdf.co/v1/file/upload/url?url=" . $fileName;

      // Create request
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-api-key: " . $apiKey));
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      // Execute request
      $result = curl_exec($curl);
    ?>
    ```
  </Tab>
</Tabs>
