Skip to main content
routa.media stores a file in Routa and retrieves the media object. For the concept, the accepted types and the limits, see Media.
media.upload() exists from version 0.3.0. The sample of a template header, used to create the template, does not go through here: use templates.uploadMedia(). The file each template send carries does.

upload

There are two modes, and you use exactly one of them. The two form a type union: mixing them, or passing file without contentType, does not compile.

Upload the bytes

The SDK sends the bytes as the request body, with no JSON or multipart.
  • contentType is sent as the Content-Type of the request, and that is how the API finds out the type. The SDK does not read it from the type of a Blob.
  • It must be exactly one of the accepted types, with no parameters such as ; charset=....
  • The first bytes of the file must match the type. A PNG declared as image/jpeg is refused.
  • Do not pass application/json as contentType: the API reads it as URL mode and responds media_source_url_invalid.

Ask Routa to download a URL

Routa downloads a public http or https URL and stores the file. The SDK sends it as JSON, in { "source_url": ... }.

The result

The upload is synchronous: when it finishes, the Media already has status: 'ready' and a signed url, valid for 15 minutes. retrieve() issues a new URL. Keep the id. From 0.5.0, messages.send() accepts it as the media header of a template, in headerParameter.mediaId. No method sends a media message yet: see what the SDK does not support yet.

retrieve

Errors

The SDK does not check the size or the type of the file. The API decides, and a rule copied into the SDK would go stale. A refused upload throws: None of these errors sets param. The 413 arrives as a base RoutaApiError because the SDK has no subclass for it.

Not idempotent

POST /v1/media does not read Idempotency-Key, so the SDK does not send one. The client still retries a network failure or a 5xx. If the first attempt had already stored the file and only the response was lost, the retry stores a second copy, with another id.
Set maxRetries: 0 on the client if a duplicate copy matters more to you than resilience to an unstable connection. See Configuration.