1

I am trying to upload a video via REST API to LinkedIn. I have completed all the steps and everything is working fine except for the video upload API.

Here is the curl command for upload videos, mentioned on the documentation of LinkedIn:

curl -v -H "Content-Type:application/octet-stream" --upload-file docs/short_video.mp4 'https://api.linkedin.com/mediaUpload/C5400AQHpR1ANqMWqNA/uploadedVideo/0?ca=vector_feedshare&cn=uploads_secure&ccn=ambry-video&m=AQLEZ2pjh43pagYYYXRaCyztOykwDzluHkkYTbsMjNUzivrEOeObw9h3&app=1234&sync=1&v=beta&ut=1KeEm4JnMnJpo1'

When I run this curl command, the video uploaded successfully and I got the status AVAILABLE, but the same thing with python post requests is not working.

Here is the python code that I converted from the curl command:

    headers = {
        'Content-Type': 'application/octet-stream'
    }

    filePath = 'docs/short_video.mp4'

    files_data = {
        'upload_file': (open(filePath, 'rb'))
    }

    post_url = 'https://api.linkedin.com/mediaUpload/C5400AQHpR1ANqMWqNA/uploadedVideo/0?ca=vector_feedshare&cn=uploads_secure&ccn=ambry-video&m=AQLEZ2pjh43pagYYYXRaCyztOykwDzluHkkYTbsMjNUzivrEOeObw9h3&app=1234&sync=1&v=beta&ut=1KeEm4JnMnJpo1'

    req = requests.put(post_url, files=files_data, headers=headers)

I am not sure what I am doing wrong in my python code. Is there something that I am missing? Any kind of help would be greatly appreciated.

1 Answer 1

0
upload_request_data = response_data['value']['uploadMechanism'][
            'com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest'
        ]
response = requests.post(
    upload_request_data['uploadUrl'],
    headers=upload_request_data['headers'],
    data=open(filePath, 'rb'),
)
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as explanations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Jun 28, 2022 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.