# Nestjs call rest attachments api not working

**URL:** <https://community.developer.atlassian.com/t/nestjs-call-rest-attachments-api-not-working/58674>\
**Category:** Jira Cloud\
**Tags:** attachment\
**Created:** [May 27, 2022, 1:50pm UTC](https://community.developer.atlassian.com/t/nestjs-call-rest-attachments-api-not-working/58674 "2022-05-27T13:50:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![FranciscoSilva](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@FranciscoSilva](https://community.developer.atlassian.com/u/FranciscoSilva)\
**Post date:** [May 27, 2022, 1:50pm UTC](https://community.developer.atlassian.com/t/nestjs-call-rest-attachments-api-not-working/58674/1 "2022-05-27T13:50:49Z")

</div>

Im using nestjs to create an API that receives a file and then I want to send that file as attachment to Jira API but I can’t make it work

```auto
async addAttachment(
    @Param('id') id: string,
    @UploadedFile() file: Express.Multer.File
  ) {
  // logging the files gives:

 {
  fieldname: 'file',
  originalname: 'cockpit-print.png',
  encoding: '7bit',
  mimetype: 'image/png',
  buffer: <Buffer 61 05 00 ... 93621 more bytes>,
  size: 93671
}

```

then in order to call jira api I do:

```auto
    const attachmentHeaders = {
      headers: {
        Authorization: `Basic ${this.credentials}`,
        Accept: 'application/json',
        'X-Atlassian-Token': 'no-check',
      },
    };

    const form = new FormData();
    const stream = Readable.from(file.buffer.toString());
    form.append('file', stream);
    return axios.post(
      `${this.baseUrl}issue/${id}/attachments`,
      form,
      attachmentHeaders
    );
}

```

but this gives the error: “Error: Request failed with status code 415”

any ideas? ty

---

<div class="post-metadata">

**Author:** ![FranciscoSilva](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@FranciscoSilva](https://community.developer.atlassian.com/u/FranciscoSilva)\
**Post date:** [June 8, 2022, 8:43am UTC](https://community.developer.atlassian.com/t/nestjs-call-rest-attachments-api-not-working/58674/2 "2022-06-08T08:43:40Z")

</div>

If someone is struggling here is the solution 🙂

```auto
    const form = new FormData();
    form.append('file', file.buffer, file.originalname);

    const attachmentHeaders = {
      headers: {
        Authorization: `Basic ${this.credentials}`,
        Accept: 'application/json',
        'X-Atlassian-Token': 'no-check',
        ...form.getHeaders(),
      },
    };

```
