# Como fazer upload de arquivos através da API?

**URL:** <https://meta.discourse.org/t/how-to-upload-files-through-the-api/204310>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [23 Setembro , 2021 13:36 UTC](https://meta.discourse.org/t/how-to-upload-files-through-the-api/204310 "2021-09-23T13:36:45Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)\
**Post date:** [23 Setembro , 2021 13:36 UTC](https://meta.discourse.org/t/how-to-upload-files-through-the-api/204310/1 "2021-09-23T13:36:45Z")

</div>

Estou tentando descobrir como permitir uploads de arquivos [via API.](https://docs.discourse.org/#operation/createUpload) Vi este post útil: [How to upload a file via API and get it's URL? - #3 by Daniil\_Bazhenov](https://meta.discourse.org/t/how-to-upload-a-file-via-api-and-get-its-url/123732/3),

mas ele não fornece a sintaxe real — e é nisso que estou tendo dificuldade. Alguém tem a sintaxe real para a chamada AJAX?

Isso é o que tenho:

```plaintext
 method: "post",
      url: [site]/uploads.json,
      contentType: "multipart/form-data",
      data: {
        type: "composer",
        file: '/path_to_file_from_users_machine'
      },
      headers: {
        "User-Api-Key": key
      },
      dataType: "json",
    }).then((result)=>{

```

Mas isso retorna uma resposta 422 — algo não está bem com essa sintaxe. Como posso fazer funcionar?

---

_[View the full topic](https://meta.discourse.org/t/how-to-upload-files-through-the-api/204310)._
