> ## 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 Small File

> Uploads a small (up to 100KB) local file as a temporary file in PDF.co storage. Note: temporary files are automatically permanently removed after 1 hour.

## `POST /v1/file/upload`

## 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 request = require('request');
    var fs = require('fs');
    var options = {
      'method': 'POST',
      'url': 'https://api.pdf.co/v1/file/upload',
      'headers': {
        'x-api-key': '{{x-api-key}}'
      },
      formData: {
        'file': {
          'value': fs.createReadStream('/path/to/file'),
          'options': {
            'filename': 'filename'
            'contentType': null
          }
        }
      }
    };
    request(options, function (error, response) {
      if (error) throw new Error(error);
      let data = JSON.parse(response.body);
      console.log(data);
    });
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    url = "https://api.pdf.co/v1/file/upload"

    payload = {}
    files = [
    		('file', open('/path/to/file','rb'))
    ]
    headers = {
    		'x-api-key': '{{x-api-key}}'
    }

    response = requests.request("POST", url, headers=headers, json = payload, files = files)

    print(response.text.encode('utf8'))
    ```
  </Tab>

  <Tab title="PHP">
    ```php theme={null}
    <?php

    $curl = curl_init();

    curl_setopt_array($curl, array(
    		CURLOPT_URL => "https://api.pdf.co/v1/file/upload",
    		CURLOPT_RETURNTRANSFER => true,
    		CURLOPT_ENCODING => "",
    		CURLOPT_MAXREDIRS => 10,
    		CURLOPT_TIMEOUT => 0,
    		CURLOPT_FOLLOWLOCATION => true,
    		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    		CURLOPT_CUSTOMREQUEST => "POST",
    		CURLOPT_POSTFIELDS => array('file'=> new CURLFILE('/path/to/file')),
    		CURLOPT_HTTPHEADER => array(
    				"x-api-key: {{x-api-key}}"
    		),
    ));

    $response = json_decode(curl_exec($curl));

    curl_close($curl);
    echo "<h2>Output:</h2><pre>", var_export($response, true), "</pre>";
    ?>
    ```
  </Tab>

  <Tab title="C#">
    ```csharp theme={null}
    using System;
    using RestSharp;
    namespace HelloWorldApplication {
    		class HelloWorld {
    				static void Main(string[] args) {
    						var client = new RestClient("https://api.pdf.co/v1/file/upload");
    						client.Timeout = -1;
    						var request = new RestRequest(Method.POST);
    						request.AddHeader("x-api-key", "{{x-api-key}}");
    						request.AddFile("file", "/path/to/file");
    						IRestResponse response = client.Execute(request);
    						Console.WriteLine(response.Content);
    				}
    		}
    }
    ```
  </Tab>
</Tabs>
