3

I am trying to upload a video in Video Indexer API using Python:

import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Content-Type': 'multipart/form-data',
    'Ocp-Apim-Subscription-Key': '******************',
}

params = urllib.parse.urlencode({
    # Request parameters
    'name': 'xxxx',
    'privacy': 'Private',
    'language': 'English',

})

try:
    conn = http.client.HTTPSConnection('videobreakdown.azure-api.net')
    conn.request("POST", "/Breakdowns/Api/Partner/Breakdowns?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

But I am not able to specify how to give the video file in the {body} section.

Kindly help me.

oguz ismail
  • 1
  • 16
  • 47
  • 69

1 Answers1

0

This works for me:

import requests
import urllib.parse
import json

headers = {
    'Ocp-Apim-Subscription-Key': 'YOUR-API-KEY',
}

form_data = {'file': open('YOUR-VIDEO.mp4', 'rb')}

params = urllib.parse.urlencode({
    'name': 'video.mp4',
    'privacy': 'Private',
    'language': 'English',
})

try:
    url = 'https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns?'
    r = requests.post(url, params=params, files=form_data, headers=headers)
    print(r.url)
    print(json.dumps(r.json(), indent=2))
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))
Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130