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

# Baixar mídia

> Baixe mídia recebida de forma unificada.

Baixa a mídia de uma mensagem recebida. O WhatsApp entrega mídias criptografadas;
este endpoint descriptografa usando os metadados que chegam no webhook
(`media_key`, `mimetype`, `direct_path` ou `url`, e os hashes).

Defina `base64: true` para receber o conteúdo embutido na resposta, ou use
`async` para downloads grandes em segundo plano.

<Tip>
  Os campos necessários (`media_key`, `mimetype`, `file_sha256` etc.) vêm no
  payload do webhook de mensagem recebida — repasse-os diretamente para cá.
</Tip>


## OpenAPI

````yaml api-reference/openapi.json POST /api/v1/media/download
openapi: 3.1.0
info:
  title: D-API - Infraestrutura WhatsApp Completa
  description: >-
    Solução escalável e robusta para gestores de automação, SaaS e usuários
    finais que precisam de uma integração WhatsApp confiável. Oferece múltiplas
    instâncias simultâneas, webhooks em tempo real, dashboard intuitivo e API
    REST documentada com 99.9% de uptime e latência inferior a 30ms.
  version: 1.2.0
  contact:
    name: Suporte D-API
    email: suporte@d-api.cloud
    url: https://d-api.cloud
servers:
  - url: https://api.d-api.cloud
    description: Produção
security:
  - ApiKeyAuth: []
tags:
  - name: Início
    description: Endpoints base
  - name: Sessões
    description: Endpoints para gerenciamento de sessões
  - name: Mensagens
    description: Endpoints para envio de mensagens
  - name: Ligações URA
    description: >-
      Disparo de ligações de voz (URA): individual ou em massa, com áudio ou
      fluxo IVR.
  - name: SMS
    description: 'Envio de SMS: individual ou em massa.'
paths:
  /api/v1/media/download:
    post:
      tags:
        - Mídia
      summary: Baixar mídia (unificado)
      description: >-
        Baixa qualquer tipo de mídia (imagem, vídeo, áudio, documento) usando as
        informações de mídia fornecidas. Requer media_key e url ou direct_path.
        Se 'base64: true', retorna dados em base64. Caso contrário, faz upload
        para S3 e retorna 'media_url'.
      operationId: postApiV1MediaDownload
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                sessionId:
                  minLength: 1
                  type: string
                url:
                  type: string
                direct_path:
                  type: string
                media_key:
                  minLength: 1
                  type: string
                mimetype:
                  minLength: 1
                  type: string
                file_enc_sha256:
                  type: string
                file_sha256:
                  type: string
                file_length:
                  type: number
                async:
                  type: string
                base64:
                  type: boolean
              required:
                - sessionId
                - media_key
                - mimetype
          multipart/form-data:
            schema:
              type: object
              properties:
                sessionId:
                  minLength: 1
                  type: string
                url:
                  type: string
                direct_path:
                  type: string
                media_key:
                  minLength: 1
                  type: string
                mimetype:
                  minLength: 1
                  type: string
                file_enc_sha256:
                  type: string
                file_sha256:
                  type: string
                file_length:
                  type: number
                async:
                  type: string
                base64:
                  type: boolean
              required:
                - sessionId
                - media_key
                - mimetype
          text/plain:
            schema:
              type: object
              properties:
                sessionId:
                  minLength: 1
                  type: string
                url:
                  type: string
                direct_path:
                  type: string
                media_key:
                  minLength: 1
                  type: string
                mimetype:
                  minLength: 1
                  type: string
                file_enc_sha256:
                  type: string
                file_sha256:
                  type: string
                file_length:
                  type: number
                async:
                  type: string
                base64:
                  type: boolean
              required:
                - sessionId
                - media_key
                - mimetype
      responses:
        '200':
          description: Resposta bem-sucedida
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: 'API Key para autenticação. Formato: <API_KEY>'

````