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

# Upload attachment

> 
**MESSAGE ATTACHMENT UPLOAD**

Uploads a file and creates an attachment record.
The attachment can then be used to send media messages (images, audio, video, documents).

---

### 📋 **How to use**

1. Upload the file through this endpoint
2. Keep the `_id` it returns
3. Use that `_id` on the message sending endpoints (`send-image`, `send-audio`, `send-video`, `send-document`)

---

### 📁 **Supported file types**

- **IMAGE**: images (JPG, PNG, GIF, WEBP)
- **AUDIO**: audio (MP3, OGG, AAC, AMR)
- **VIDEO**: video (MP4, 3GP)
- **DOCUMENT**: documents (PDF, DOC, DOCX, XLS, XLSX, PPT, TXT)
- **STICKER**: WhatsApp stickers (WEBP)

---

### 🔄 **Full media sending flow**

```
1. POST /resource/upload-attachment (with file and fileType)
   → Returns: { _id: "65f1a2b3c4d5...", external_url: "https://...", ... }

2. POST /messages/send-image (with conversationId and attachment)
   → Sends the image to the contact
```

---

### 📝 **Example**

**Request:**
```http
POST /resource/upload-attachment
Content-Type: multipart/form-data

{
  "file": [binary file],
  "fileType": "IMAGE"
}
```

**Response:**
```json
{
  "_id": "65f1a2b3c4d5e6f7g8h9i0j1",
  "extension": "png",
  "external_url": "https://s3.amazonaws.com/bucket/file.png",
  "file_type": "IMAGE",
  "meta": {
    "mimeType": "image/png",
    "size": 102400,
    "fileName": "foto.png",
    "resourceUrl": "https://s3.amazonaws.com/bucket/file.png"
  },
  "company": "65f...",
  "createdAt": "2024-01-15T10:30:00.000Z"
}
```

**Then send the image:**
```json
POST /messages/send-image

{
  "conversationId": "65f...",
  "message": {
    "content": "Check out this image!",
    "contentType": "IMAGE",
    "attachment": "65f1a2b3c4d5e6f7g8h9i0j1"
  }
}
```

---

### ⚠️ **Important notes**

1. **Maximum size**: varies by file type and channel (WhatsApp has its own limits)
2. **Accepted formats**: only formats supported by WhatsApp
3. **Storage**: files are stored on AWS S3
4. **Public URL**: the returned URL is public and directly accessible
5. **Reuse**: the same attachment can be used in several messages
6. **Persistence**: attachments are stored permanently
    



## OpenAPI

````yaml /en/openapi.json post /v1/resource/upload-attachment
openapi: 3.0.0
info:
  title: Nuvia API - Company
  description: API documentation for companies
  version: '1.0'
  contact: {}
servers:
  - url: https://api.nuvia.ai
security: []
tags:
  - name: messages
    x-group: Mensagens
  - name: contacts
    x-group: Contatos
  - name: campaigns
    x-group: Campanhas
  - name: tables
    x-group: Tabelas e Listas
  - name: agents
    x-group: Agentes
  - name: conversations
    x-group: Conversas
  - name: inboxes
    x-group: Caixas de Entrada
  - name: knowledge
    x-group: Base de Conhecimento
  - name: Webhooks
    x-group: Webhooks
  - name: campaign-enrollments
    x-group: Inscrições em Campanha
  - name: custom-fields
    x-group: Campos Customizados
  - name: resources
    x-group: Arquivos e Anexos
paths:
  /v1/resource/upload-attachment:
    post:
      tags:
        - resources
      summary: Upload attachment
      description: >-

        **MESSAGE ATTACHMENT UPLOAD**


        Uploads a file and creates an attachment record.

        The attachment can then be used to send media messages (images, audio,
        video, documents).


        ---


        ### 📋 **How to use**


        1. Upload the file through this endpoint

        2. Keep the `_id` it returns

        3. Use that `_id` on the message sending endpoints (`send-image`,
        `send-audio`, `send-video`, `send-document`)


        ---


        ### 📁 **Supported file types**


        - **IMAGE**: images (JPG, PNG, GIF, WEBP)

        - **AUDIO**: audio (MP3, OGG, AAC, AMR)

        - **VIDEO**: video (MP4, 3GP)

        - **DOCUMENT**: documents (PDF, DOC, DOCX, XLS, XLSX, PPT, TXT)

        - **STICKER**: WhatsApp stickers (WEBP)


        ---


        ### 🔄 **Full media sending flow**


        ```

        1. POST /resource/upload-attachment (with file and fileType)
           → Returns: { _id: "65f1a2b3c4d5...", external_url: "https://...", ... }

        2. POST /messages/send-image (with conversationId and attachment)
           → Sends the image to the contact
        ```


        ---


        ### 📝 **Example**


        **Request:**

        ```http

        POST /resource/upload-attachment

        Content-Type: multipart/form-data


        {
          "file": [binary file],
          "fileType": "IMAGE"
        }

        ```


        **Response:**

        ```json

        {
          "_id": "65f1a2b3c4d5e6f7g8h9i0j1",
          "extension": "png",
          "external_url": "https://s3.amazonaws.com/bucket/file.png",
          "file_type": "IMAGE",
          "meta": {
            "mimeType": "image/png",
            "size": 102400,
            "fileName": "foto.png",
            "resourceUrl": "https://s3.amazonaws.com/bucket/file.png"
          },
          "company": "65f...",
          "createdAt": "2024-01-15T10:30:00.000Z"
        }

        ```


        **Then send the image:**

        ```json

        POST /messages/send-image


        {
          "conversationId": "65f...",
          "message": {
            "content": "Check out this image!",
            "contentType": "IMAGE",
            "attachment": "65f1a2b3c4d5e6f7g8h9i0j1"
          }
        }

        ```


        ---


        ### ⚠️ **Important notes**


        1. **Maximum size**: varies by file type and channel (WhatsApp has its
        own limits)

        2. **Accepted formats**: only formats supported by WhatsApp

        3. **Storage**: files are stored on AWS S3

        4. **Public URL**: the returned URL is public and directly accessible

        5. **Reuse**: the same attachment can be used in several messages

        6. **Persistence**: attachments are stored permanently
            
      operationId: ResourceController_uploadAttachment
      parameters:
        - name: x-company-id
          in: header
          description: >-
            Target company identifier. Required only for global API keys
            (type=global). Ignored for company API keys and human users.
          required: false
          schema:
            type: string
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
                - fileType
              properties:
                file:
                  type: string
                  format: binary
                  description: Arquivo para upload
                fileType:
                  type: string
                  enum:
                    - IMAGE
                    - AUDIO
                    - VIDEO
                    - DOCUMENT
                    - STICKER
                  description: Tipo do arquivo (IMAGE, AUDIO, VIDEO, DOCUMENT, STICKER)
      responses:
        '201':
          description: Attachment created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AttachmentResponseDto'
        '400':
          description: Invalid data
        '401':
          description: Invalid or expired token
        '403':
          description: You do not have permission to access this resource
      security:
        - JWT-auth: []
components:
  schemas:
    AttachmentResponseDto:
      type: object
      properties:
        _id:
          type: string
          description: Attachment ID.
        s3_key:
          type: string
          description: Storage key of the object, used to derive the signed URL.
        extension:
          type: string
          description: File extension (jpg, png, pdf, and so on).
        external_url:
          type: string
          description: >-
            Public file URL. Deprecated: prefer deriving a signed URL from
            `s3_key`.
        file_type:
          type: string
          enum:
            - IMAGE
            - AUDIO
            - VIDEO
            - DOCUMENT
            - STICKER
          description: 'File type: IMAGE, AUDIO, VIDEO, DOCUMENT, or STICKER.'
        meta:
          type: object
          description: >-
            Additional file metadata: `mimeType`, `size`, `fileName`, and
            others.
          properties:
            mimeType:
              description: Tipo MIME do arquivo
              type: string
            size:
              description: Tamanho do arquivo em bytes
              type: number
            fileName:
              description: Nome original do arquivo
              type: string
            resourceUrl:
              description: URL do recurso no S3
              type: string
        company:
          description: Company that owns the attachment.
        createdAt:
          description: When the attachment was created.
        updatedAt:
          description: When the attachment was last updated.
      required:
        - extension
        - external_url
        - file_type
        - company
  securitySchemes:
    JWT-auth:
      scheme: bearer
      bearerFormat: JWT
      type: http
      description: Token JWT de autenticação

````