Latest Legacy

Upload Media

This API lets you upload media files to be used in sending MMS messages. Plivo supports up to 10 attachments in an upload API/SDK call with a maximum of 2MB per attachment. 

  • Media uploaded and sent to customers through MMS is saved in the system for 1 year.
  • Unused media (media that is uploaded but not used for sending an MMS message) is deleted after 6 hours.

API Endpoint

POST https://api.plivo.com/v1/Account/{auth_id}/Media/

Headers

The content-type header should be set to multipart/form-data

Arguments

filetype(file)Required This argument allows you to attach one or more (max 10) files as attachments in the body of the request.

Returns

Returns a JSON response containing the list of media objects uploaded.

Response

HTTP Status Code: 200

{
    "api_id": "<api_id>",
    "objects": [
        {
            "content_type": "image/jpeg",
            "file_name": "sample_file1.jpg",
            "media_id": "<media_id>",
            "size": 85277,
            "status": "success",
            "status_code": 201,
            "upload_time": "2021-02-17T07:16:09.153289Z",
            "media_url": "https://media.plivo.com/Account/<auth_id>/Media/<media_id>"
        },
        {
            "content_type": "image/png",
            "file_name": "sample_file2.png",
            "media_id": "<media_id>",
            "size": 16709,
            "status": "success",
            "status_code": 201,
            "upload_time": "2021-02-18T11:21:55.972100055Z",
            "media_url": "https://media.plivo.com/Account/<auth_id>/Media/<media_id>"
        }
    ]
}

Example Request

1
2
3
4
5
import plivo
client = plivo.RestClient("<auth_id>", "<auth_token>")
response = client.media.upload(['<video/image file path>',
'<video/image file path>'])
print(response)
1
2
3
4
5
6
7
8
9
10
11
12
13
require 'rubygems'
require 'plivo'

include Plivo
include Plivo::Exceptions

api = RestClient.new("<auth_id>","<auth_token>")
begin
 response = api.media.upload(['file_to_upload1''])
 puts response
 rescue PlivoRESTError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
let plivo = require('plivo');

let client = new plivo.Client('<auth_id>', '<auth_token>');
client.media.upload(["/tmp/test.jpeg","/tmp/test2.jpeg"]).then(
  function (media) {
    console.log("\n============ response ===========\n", media)
  }
).catch(function (response) {
  console.log("\n============ Error :: ===========\n", response);
});
1
2
3
4
5
6
7
8
9
10
11
12
<?php
require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("<auth_id>","<auth_token>");
try {
  $response = $client->media->upload(['path or url','xxx.jpg']); #file path
  print_r($response);
}
catch (PlivoRestException $ex) {
    print_r($ex);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package com.plivo.api;
import java.io.IOException;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.media.Media;

public class Test {
    public static void main(String[] args) {
      Plivo.init("<auth_id>", "<auth_token>");
      try {
        MediaResponse mediaResponse = Media.creator(new String[]{"upload_file1","upload_file2"}).create();
        System.out.println(mediaResponse);
      } catch (IOException e) {
        e.printStackTrace();
      } catch (PlivoRestException e) {
        e.printStackTrace();
      }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using Plivo;
using Plivo.Exception;

namespace SdkTestDotnet
{
    class Program
    {
        static void Main(string[] args)
        {
            var api = new PlivoApi("<auth_id>","<auth_token>");
            try
            {
                string[] files = { "file_to_upload1", "file_to_upload2"};
                var response = api.Media.Upload(files);
                Console.WriteLine(response);
            }
            catch (PlivoRestException e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
    }
}
1
2
3
4
curl -i --user auth_id:auth_token \
  -H "Content-Type: multipart/form-data" \
  --form 'file=@local_path_of_image'\
  https://api.plivo.com/v1/Account/{auth_id}/Media/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main

import (
	"fmt"

	plivo "github.com/plivo/plivo-go/v7"
)

func main() {

	// MAIN ACCOUNT
	client, err := plivo.NewClient("<auth_id>",
		"<auth_token>",
		&plivo.ClientOptions{})
	if err != nil {
		panic(err)
	}

	//upload media
	uploadResp, err := client.Media.Upload(plivo.MediaUpload{
		UploadFiles: []plivo.Files{
			plivo.Files{
				FilePath:    "<file_path>",
				ContentType: "<content_type>",
			},
		},
	},
	)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Response: %#v\n", uploadResp)
}