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

# Upload media

> Upload media file to Telnyx so it can be used with other Telnyx services



## OpenAPI

````yaml https://telnyx-openapi-ng.s3.us-east-1.amazonaws.com/real-time-communications/media-storage.yml post /media
openapi: 3.1.0
info:
  title: Telnyx Media Storage API
  version: 2.0.0
  description: API for Media storage.
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
security:
  - bearerAuth: []
paths:
  /media:
    post:
      tags:
        - Media Storage API
      summary: Upload media
      description: Upload media file to Telnyx so it can be used with other Telnyx services
      operationId: CreateMediaStorage
      requestBody:
        description: Upload media request
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UploadMediaRequest'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/UploadMediaMultipartRequest'
      responses:
        '201':
          $ref: '#/components/responses/MediaResponse'
        '401':
          $ref: '#/components/responses/media-storage_GenericErrorResponse'
        '422':
          $ref: '#/components/responses/media-storage_GenericErrorResponse'
        default:
          $ref: '#/components/responses/media-storage_GenericErrorResponse'
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Telnyx from 'telnyx';


            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });


            const response = await client.media.upload({ media_url:
            'http://www.example.com/audio.mp3' });


            console.log(response.data);
        - lang: Python
          source: |-
            import os
            from telnyx import Telnyx

            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )
            response = client.media.upload(
                media_url="http://www.example.com/audio.mp3",
            )
            print(response.data)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tresponse, err := client.Media.Upload(context.TODO(), telnyx.MediaUploadParams{\n\t\tMediaURL: \"http://www.example.com/audio.mp3\",\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.Data)\n}\n"
        - lang: Java
          source: |-
            package com.telnyx.sdk.example;

            import com.telnyx.sdk.client.TelnyxClient;
            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
            import com.telnyx.sdk.models.media.MediaUploadParams;
            import com.telnyx.sdk.models.media.MediaUploadResponse;

            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    MediaUploadParams params = MediaUploadParams.builder()
                        .mediaUrl("http://www.example.com/audio.mp3")
                        .build();
                    MediaUploadResponse response = client.media().upload(params);
                }
            }
        - lang: Ruby
          source: >-
            require "telnyx"


            telnyx = Telnyx::Client.new(api_key: "My API Key")


            response = telnyx.media.upload(media_url:
            "http://www.example.com/audio.mp3")


            puts(response)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $response = $client->media->upload(
                mediaURL: 'http://www.example.com/audio.mp3',
                mediaName: 'my-file',
                ttlSecs: 86400,
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx media upload \
              --api-key 'My API Key' \
              --media-url http://www.example.com/audio.mp3
components:
  schemas:
    UploadMediaRequest:
      type: object
      title: Upload media request
      required:
        - media_url
      properties:
        media_url:
          description: >-
            The URL where the media to be stored in Telnyx network is currently
            hosted. The maximum allowed size is 20 MB.
          type: string
          example: http://www.example.com/audio.mp3
        ttl_secs:
          description: >-
            The number of seconds after which the media resource will be
            deleted, defaults to 2 days. The maximum allowed vale is 630720000,
            which translates to 20 years.
          type: integer
          example: 86400
        media_name:
          description: The unique identifier of a file.
          type: string
          example: my_file
      example:
        media_url: http://www.example.com/audio.mp3
        ttl_secs: 86400
        media_name: my-file
    UploadMediaMultipartRequest:
      type: object
      title: Upload media multipart request
      required:
        - media
      properties:
        media:
          description: The file you want to upload. The maximum allowed size is 20 MB.
          type: string
          format: binary
        ttl_secs:
          description: >-
            The number of seconds after which the media resource will be
            deleted, defaults to 2 days. The maximum allowed vale is 630720000,
            which translates to 20 years.
          type: integer
          example: 86400
        media_name:
          description: The unique identifier of a file.
          type: string
          example: my_file
      example:
        media: string($binary)
        ttl_secs: 86400
        media_name: my-file
    MediaResource:
      type: object
      title: Media Resource
      properties:
        media_name:
          description: Uniquely identifies a media resource.
          type: string
        expires_at:
          description: >-
            ISO 8601 formatted date of when the media resource will expire and
            be deleted.
          type: string
          example: '2020-01-23T18:10:02.574Z'
        created_at:
          type: string
          description: ISO 8601 formatted date of when the media resource was created
          example: '2019-01-23T18:10:02.574Z'
        updated_at:
          type: string
          description: ISO 8601 formatted date of when the media resource was last updated
          example: '2019-01-23T18:10:02.574Z'
        content_type:
          type: string
          description: Content type of the file
          example: application/xml
      example:
        media_name: f5586561-8ff0-4291-a0ac-84fe544797bd
        expires_at: '2020-01-23T18:10:02.574Z'
        created_at: '2019-01-23T18:10:02.574Z'
        updated_at: '2019-01-23T18:10:02.574Z'
        content_type: application/xml
    media-storage_Errors:
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/media-storage_Error'
      type: object
    media-storage_Error:
      required:
        - code
        - title
      properties:
        code:
          type: string
        title:
          type: string
        detail:
          type: string
        source:
          type: object
          properties:
            pointer:
              description: JSON pointer (RFC6901) to the offending entity.
              type: string
            parameter:
              description: Indicates which query parameter caused the error.
              type: string
        meta:
          type: object
          additionalProperties: true
      type: object
  responses:
    MediaResponse:
      description: A response describing a media resource
      content:
        application/json:
          schema:
            type: object
            title: Media resource response
            properties:
              data:
                $ref: '#/components/schemas/MediaResource'
    media-storage_GenericErrorResponse:
      description: Unexpected error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/media-storage_Errors'
  securitySchemes:
    bearerAuth:
      scheme: bearer
      type: http

````