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

# Using Files

Some API resources may have relationships with files. Examples may be:

* a user picture ;
* a work-contract attachment ;
* etc...

<Steps>
  <Step title="Upload a file">
    First upload a file through the file-upload API endpoint.

    <CodeGroup>
      ```http HTTP Request theme={null}
      POST /lucca-files/api/uploads HTTP/1.1
      Host: example.ilucca.net
      Authorization: lucca application={API_KEY}
      Accept: application/json
      Content-Type: multipart/form-data; boundary=---abc

      -----abc
      Content-Disposition: form-data; name=""; filename="test.pdf"

      -----abc--
      ```

      ```curl Curl Request theme={null}
      curl --location 'https://example.ilucca.net/lucca-files/api/uploads' \
      --header 'Authorization: lucca application={API_KEY}' \
      --header 'Accept: application/json' \
      --form '=@"/C:/foo/bar/test.pdf"'
      ```

      ```json Response theme={null}
      {
          "id": "d18261af-3b70-442f-94c2-3995cc8ca02c",
          "name": "test.pdf",
          "createdAt": "2024-11-21T14:54:14.1273553Z",
          "deletedAt": null,
          "contentLength": 3242,
          "contentType": "application/pdf",
          "extension": ".pdf",
          "totalPages": 1
      }
      ```
    </CodeGroup>

    <Tip>Make sure to keep the id given in the response, you'll need it later.</Tip>
  </Step>

  <Step title="Set the file id as a reference on the object">
    You then need to set the uploaded file id on the corresponding resource.

    <CodeGroup>
      ```json User picture example theme={null}
      PUT /api/v3/users/416 HTTP/1.1
      Host: example.ilucca.net
      Authorization: lucca application={API_KEY}
      Accept: application/json
      Content-Type: application/json

      {
          "picture": {
              "id": "618d5bac-2f38-4d5b-8ba3-981733dffeff"
          }
      }
      ```

      ```json ExtendedData example theme={null}
      PUT /api/v3/users/:idUser?fields=extendedData,id HTTP/1.1
      Host: example.ilucca.net
      Authorization: lucca application={API_KEY}
      Accept: application/json
      Content-Type: application/json

      {
          "e_Visite-medicale": [
              {
              "value": {
                  "e_Date-de-la-visite": { "value": null },
                  "e_Attestation": {
                  "value": { "id": "552cb7db-b7e2-4f39-a675-c4b140f41eea" } // File id
                  },
                  "e_Convocation": { "value": null },
                  "e_Date-de-la-prochaine-visite": { "value": null },
                  "e_Preconisations-medicales": { "value": null }
              },
              "isNew": true,
              "id": 0
              }
          ]
      }
      ```
    </CodeGroup>
  </Step>
</Steps>
