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

# Request a media upload

> A presigned URL and the exact upload headers; the event carries only the reference and the hash.



## OpenAPI

````yaml openapi/en/cell.json POST /v1/media/uploads
openapi: 3.1.0
info:
  title: Niadra data API
  version: '1'
  description: >-
    Writing, context, history, objects, identity, privacy and governance of one
    space. Every space has a stable address, with the space and the region in
    its name.
servers:
  - url: https://{space}.{region}.api.niadra.com
    variables:
      space:
        default: acme-prod
        description: The space, which comes in the source key.
      region:
        default: us-east-1
        description: The region of the space, which also comes in the key.
security: []
paths:
  /v1/media/uploads:
    post:
      tags:
        - ingest
      summary: Request a media upload
      description: >-
        Reserves a place for an audio file or attachment and returns a presigned
        `upload_url`. Upload the bytes with `PUT` sending exactly the headers in
        `upload_headers`: the store refuses any other bytes, which is how the
        SHA-256 you declared is enforced. Then send the event with
        `content.media_ref` and `content.media_sha256`. Pass `subject` so a
        `forget` reaches the file even if no event ever references it.


        **Authentication.** Source key: `Authorization: Bearer nia_sk_...`.
        Required scope: `track`.
      operationId: media_upload_v1_media_uploads_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MediaUploadIn'
            example:
              content_type: audio/ogg
              size_bytes: 48213
              sha256: a3f1c2d4e5b6978812ab34cd56ef7890a1b2c3d4e5f60718293a4b5c6d7e8f90
              subject:
                type: phone_e164
                value: '+14155550123'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MediaUploadResponse'
              example:
                media_ref: med_01J8ZM2
                upload_url: https://uploads.us-east-1.api.niadra.com/med_01J8ZM2?sig=...
                upload_headers:
                  Content-Type: audio/ogg
                  x-amz-checksum-sha256: o/HC1OW2l4gSqzTNVu94kKGyw9Tl9gcYKTpLXG1+j5A=
                expires_at: '2026-09-22T17:17:03Z'
          description: The upload slot, valid until `expires_at`.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The request does not match the contract.
      security:
        - sourceKey: []
      x-codeSamples:
        - lang: python
          label: Python
          source: >-
            # Reserves the upload, sends the bytes with the exact
            upload_headers, returns the reference

            media = niadra.upload_media(audio_bytes, "audio/ogg",
            subject=phone("+14155550123"))


            niadra.track({
                "channel": "whatsapp",
                "conversation_id": "wa-8812",
                "handles": [phone("+14155550123")],
                "speaker": {"role": "customer"},
                "content": {"type": "audio", "media_ref": media.media_ref, "media_sha256": media.media_sha256},
            })
        - lang: typescript
          label: TypeScript
          source: >-
            // Reserves the upload, sends the bytes with the exact
            upload_headers, returns the reference

            const { data: media } = await niadra.uploadMedia({
              data: audioBytes,
              content_type: "audio/ogg",
              subject: handles.phone("+14155550123"),
            });


            niadra.track({
              channel: "whatsapp",
              conversation_id: "wa-8812",
              handles: [handles.phone("+14155550123")],
              speaker: "customer",
              content: { type: "audio", media_ref: media!.media_ref, media_sha256: media!.media_sha256 },
            });
components:
  schemas:
    MediaUploadIn:
      additionalProperties: false
      properties:
        content_type:
          maxLength: 256
          minLength: 1
          title: Content Type
          type: string
        sha256:
          pattern: ^[0-9a-f]{64}$
          title: Sha256
          type: string
        size_bytes:
          exclusiveMinimum: 0
          maximum: 524288000
          title: Size Bytes
          type: integer
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
          description: >-
            Whose media it is. The object is stored under the subject's handle,
            so `forget` reaches it even if no event ever references it.
      required:
        - content_type
        - size_bytes
        - sha256
      title: MediaUploadIn
      type: object
    MediaUploadResponse:
      additionalProperties: false
      properties:
        expires_at:
          format: date-time
          title: Expires At
          type: string
        media_ref:
          title: Media Ref
          type: string
        upload_headers:
          additionalProperties:
            type: string
          description: >-
            Send exactly these headers with the upload; the store refuses other
            bytes.
          title: Upload Headers
          type: object
        upload_url:
          title: Upload Url
          type: string
          description: Presigned URL. Upload the bytes with `PUT`.
      required:
        - media_ref
        - upload_url
        - expires_at
      title: MediaUploadResponse
      type: object
    Problem:
      additionalProperties: false
      description: RFC 9457 problem details; `code` comes from the versioned error catalog.
      properties:
        code:
          title: Code
          type: string
        detail:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Detail
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Request Id
        status:
          title: Status
          type: integer
        title:
          title: Title
          type: string
        type:
          default: about:blank
          title: Type
          type: string
      required:
        - title
        - status
        - code
      title: Problem
      type: object
    Handle:
      additionalProperties: false
      description: >-
        An identifier of a subject in some channel or system: a phone, an
        e-mail, a CRM id.
      properties:
        scope:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: >-
            Namespace for scoped identifiers: the WhatsApp Business account for
            `wa_bsuid`, the system for `system_id`, the country for
            `gov_id_hmac`.
          title: Scope
        subject_kind:
          anyOf:
            - $ref: '#/components/schemas/SubjectKind'
            - type: 'null'
          description: Defaults to `person`, except for organization-only handle types.
        type:
          $ref: '#/components/schemas/HandleType'
        value:
          maxLength: 320
          minLength: 1
          title: Value
          type: string
          description: >-
            The identifier. Normalized on the server: E.164 for phones,
            lowercase for e-mail.
      required:
        - type
        - value
      title: Handle
      type: object
    SubjectKind:
      enum:
        - person
        - account
        - partner
      title: SubjectKind
      type: string
      description: >-
        A person, a customer organization (`account`) or an organization that
        takes part without being a customer (`partner`).
    HandleType:
      enum:
        - phone_e164
        - wa_id
        - wa_jid
        - wa_lid
        - wa_bsuid
        - email
        - gov_id_hmac
        - app_user_id
        - system_id
        - org_registry_hmac
        - email_domain
        - anon_id
      title: HandleType
      type: string
      description: >-
        The kind of identifier. The value is classified by its format, never by
        the field it came from.
  securitySchemes:
    sourceKey:
      type: http
      scheme: bearer
      description: nia_sk_...

````