Chilkat Online Tools

PowerBuilder / Plivo REST API / Upload Media

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Req
oleobject loo_Resp

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.BasicAuth = 1
loo_Http.Login = "{{auth_id}}"
loo_Http.Password = "password"

loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat_9_5_0.HttpRequest")

loo_Req.HttpVerb = "POST"
loo_Req.Path = "/v1/Account/<auth_id>/Media/"
loo_Req.ContentType = "multipart/form-data"
li_Success = loo_Req.AddFileForUpload2("file"," path to file","application/octet-stream")

loo_Req.AddHeader("Expect","100-continue")

loo_Resp = loo_Http.SynchronousRequest("api.plivo.com",443,1,loo_Req)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Req
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Req

Curl Command

curl -X POST
	-u '{{auth_id}}:password'
	--form 'file=@"/path/to/file"'
https://api.plivo.com/v1/Account/<auth_id>/Media/

Postman Collection Item JSON

{
  "name": "Upload Media",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "formdata",
      "formdata": [
        {
          "key": "file",
          "type": "file",
          "src": "/Users/mohammedhuzaif/Downloads/image.png"
        }
      ]
    },
    "url": {
      "raw": "https://api.plivo.com/v1/Account/{{auth_id}}/Media/",
      "protocol": "https",
      "host": [
        "api",
        "plivo",
        "com"
      ],
      "path": [
        "v1",
        "Account",
        "{{auth_id}}",
        "Media",
        ""
      ]
    },
    "description": "This API lets you upload media files which can be used to send MMS. Plivo supports up to a total of 10 attachments in an upload API/SDK call with a maximum of 2MB per attachment. \nMore information can be found [here](https://www.plivo.com/docs/sms/api/media#upload-media)\n\n| Arguments   | Description | Required/Conditional/Optional     |\n| :---        |    :----:   |          ---: |\n| file      | This argument allows you to attach one or more(max 10) files as attachments in the body of the request.| Required |"
  },
  "response": [
    {
      "name": "Upload Media",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "file",
              "type": "file",
              "src": "/Users/mohammedhuzaif/Downloads/image.png"
            }
          ]
        },
        "url": {
          "raw": "https://api.plivo.com/v1/Account/{{auth_id}}/Media/",
          "protocol": "https",
          "host": [
            "api",
            "plivo",
            "com"
          ],
          "path": [
            "v1",
            "Account",
            "{{auth_id}}",
            "Media",
            ""
          ]
        }
      },
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
      ],
      "cookie": [
      ],
      "body": "{\n    \"api_id\": \"<api_id>\",\n    \"objects\": [\n        {\n            \"content_type\": \"image/jpeg\",\n            \"file_name\": \"sample_file1.jpg\",\n            \"media_id\": \"<media_id>\",\n            \"size\": 85277,\n            \"status\": \"success\",\n            \"status_code\": 201,\n            \"upload_time\": \"2020-02-17T07:16:09.153289Z\",\n            \"media_url\": \"https://media.plivo.com/Account/<auth_id>/Media/<media_id>\"\n        },\n        {\n            \"content_type\": \"image/png\",\n            \"file_name\": \"sample_file2.png\",\n            \"media_id\": \"<media_id>\",\n            \"size\": 16709,\n            \"status\": \"success\",\n            \"status_code\": 201,\n            \"upload_time\": \"2020-02-18T11:21:55.972100055Z\",\n            \"media_url\": \"https://media.plivo.com/Account/<auth_id>/Media/<media_id>\"\n        }\n    ]\n}"
    }
  ]
}