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

# Upload File

> Upload and create a new file in Extend.

This endpoint accepts file contents and registers them as a File in Extend, which can be used for [running workflows](/api-reference/endpoint/run_workflow), [creating evaluation sets](/api-reference/endpoint/bulk_create_eval_set_item), [parsing](/api-reference/endpoint/parse), etc.

If an uploaded file is detected as a Word or PowerPoint document, it will be automatically converted to a PDF.

Supported file types can be found [here](/api-reference/supported_file_types).

This endpoint requires multipart form encoding. Most HTTP clients will handle this encoding automatically (see the examples).

### Headers

<ResponseField name="Content-Type" type="string">
  A `multi-part/form-data` header containing the boundary, such as
  `multi-part/form-data; boundary="..."`.
</ResponseField>

### Body

A `multipart/form-data` body containing a single `file` field and its binary data. For more information, see [the MDN documenation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST#multipart_form_submission).

The `Content-Type` field header is currently ignored and Extend will infer the type automatically based on the field's `Content-Disposition` and the file's contents.

### Response

<ResponseField name="success" type="boolean">
  A true or false value for whether the file was processed successfully or not.
</ResponseField>

<ResponseField name="file" type="File">
  A File object representing the newly created file. See the [File
  object](/api-reference/objects/file) for more details.
  **Note:** Since the file is not parsed, it will not contain `contents` nor `metadata`.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api-prod.extend.app/files/upload \
    --header 'Authorization: Bearer <token>' \
    --form 'file=@/path/to/document.pdf'
    
  ```

  ```python Python theme={null}
  import requests

  url = "https://api-prod.extend.app/files/upload"

  headers = {"Authorization": "Bearer <token>"}

  with open("document.pdf", "rb") as f:
      response = requests.post(
          url,
          files={"file": f},
          headers=headers
      )

  print(response.text)
  ```

  ```javascript JavaScript theme={null}
  const formData = new FormData();
  formData.append("file", file);

  const options = {
      method: 'POST',
      headers: {'Authorization": 'Bearer <token>'},
      body: formData
  };

  fetch("https://api-prod.extend.app/files/upload", options)
    .then(response => response.json())
    .then(response => console.log(response))
    .catch(err => console.error(err));
  ```

  ```php PHP theme={null}
  <?php

  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://api-prod.extend.app/files/upload",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => [
      "file" => new CURLFile("/path/to/document.pdf")
    ],
    CURLOPT_HTTPHEADER => [
      "Authorization: Bearer <token>"
    ],
  ]);

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
    echo "cURL Error #:" . $err;
  } else {
    echo $response;
  }
  ```

  ```go Go theme={null}
  package main

  import (
  	"bytes"
  	"fmt"
  	"io"
  	"io/ioutil"
  	"mime/multipart"
  	"net/http"
  	"os"
  )

  func main() {
  	file, _ := os.Open("document.pdf")
  	defer file.Close()

  	var requestBody bytes.Buffer
  	writer := multipart.NewWriter(&requestBody)
  	part, _ := writer.CreateFormFile("file", "document.pdf")
  	io.Copy(part, file)
  	writer.Close()

  	url := "https://api-prod.extend.app/files/upload"
  	req, _ := http.NewRequest("POST", url, &requestBody)

  	req.Header.Set("Authorization", "Bearer <token>")
  	req.Header.Set("Content-Type", writer.FormDataContentType())

  	res, _ := http.DefaultClient.Do(req)

  	defer res.Body.Close()
  	body, _ := ioutil.ReadAll(res.Body)

  	fmt.Println(res)
  	fmt.Println(string(body))
  }
  ```

  ```java Java theme={null}
  HttpResponse<String> response = Unirest.post("https://api-prod.extend.app/files/upload")
      .header("Authorization", "Bearer <token>")
      .field("file", new File("document.pdf"))
      .asString();
  ```
</RequestExample>

<ResponseExample>
  ```json Example File theme={null}
  {
    "object": "file",
    "id": "file_1234",
    "name": "example_file",
    "type": "PDF",
    "presignedUrl": "https://s3.example.com/file_1234.pdf",
    "parentFileId": "file_5678", // Optional, only set if this file is a derivative of another file
    "createdAt": "2024-01-01T00:00:00Z",
    "updatedAt": "2024-01-01T00:00:00Z"
  }
  ```
</ResponseExample>
