Download Media

Downloads a media file you previously uploaded.

Request URL


Basic Authentication

Bandwidth's messaging API leverages Basic Authentication with your API Token and API Secret. Read more about how Bandwidth secures endpoints in the Security & Credentials document.

⚠️ Caution on fetching Media ⚠️

You MUST use your API token and secret to download the media each and every time you want to access the file. We DO NOT recommend using Bandwidth's url to display/stream media files to your end-users. Providing your user-id, token, and secret to users' devices is a security risk, as they could use your credentials to access your account.

Instead, we recommend that you create a copy on your local server or a cloud storage service. Doing so allows you to specify YOUR authentication method (if any) to keep your Bandwidth account and users safe.

Example 1 of 1: Download an MP3 File

curl -X GET \
    --url '{accountId}/media/{mediaName}' \
    -u '{token}:{secret}'
try {
    ApiResponse<InputStream> response = controller.getMedia(MSG_ACCOUNT_ID, "mediaId");
    byte[] bytes = response.getResult().readAllBytes();
} catch (ApiException | IOException e) {
var response = msgClient.GetMedia(MSG_ACCOUNT_ID, mediaId);

Stream data = response.Data;

using (var fileStream = File.Create("C:\\Path\\To\\File"))
    data.Seek(0, SeekOrigin.Begin);
downloaded_media = messaging_client.get_media(MESSAGING_ACCOUNT_ID, "mediaId")
f ="file_to_write", "wb")
downloaded_media = messaging_client.get_media(MESSAGING_ACCOUNT_ID, "mediaId")
f = open("file_to_write", "wb")
var response = await messagingController.getMedia(messagingAccountId, "mediaId");
fs.writeFileSync("file_to_write", response, "binary");
$response = $messagingClient->getMedia($messagingAccountId, "mediaId");
$file = fopen("file_to_write", "wb") or die("Unable to open file");
fwrite($file, $response->getResult());

results matching ""

    No results matching ""