2

I am new at VK api.
I want to upload video via the VK API. I cannot get sample codes in my investigation in google.

Can anyone give me sample code.

ketan
  • 19,129
  • 42
  • 60
  • 98
user3702350
  • 25
  • 1
  • 7

2 Answers2

3

First you need to get http-url to upload video using this API method.

Then you should make a POST-request containing field with "video_file" which will contain your video file in binary mode. Then you should call video.save method to save changes and get video_id

SwiftStudier
  • 2,272
  • 5
  • 21
  • 43
  • step 1. I called the video.save as below; https://api.vk.com/method/video.save?access_token=xxxx&link=http://yyyy.com/4144.mp4&description=testt and get the response ; {"response":{"upload_url":"xxxxxxxx","vid":171540312,"owner_id":xxxxxx,"name":"No name","description":"testt","access_key":"xxxxxxxxxx"}} – user3702350 Oct 06 '15 at 19:43
  • Then what I use the form to post the data as ;
    but get the response ;"error_code":7,"error_msg":"no video found, check url"}
    – user3702350 Oct 06 '15 at 20:03
  • try to read what I wrote. First you need to get LINK where your will POST your VIDEO as BINARY DATA. It will be multipart-form-data-request. You do not allow to paste video-lin into "link"-parameted of video.save-method. Documentation is here https://vk.com/dev/upload_files?f=Uploading%20Videos. Change language in bottom-right corner of site – SwiftStudier Oct 06 '15 at 20:05
  • is it (https://api.vk.com/method/video.save?access_token=xxxx&link=http://yyyy.com/4144.mp4&description=testt) true link to get the video.save response in first step? – user3702350 Oct 06 '15 at 20:15
  • Too many pending edit request. But here we go: Get upload_url from first GET call to video.save request-url, next call POST to the upload_url. If you submit a link you don't need a video_file – zyrup Dec 01 '22 at 15:27
1

Using requests library:

import requests

with open('upload_file_name', 'rb') as f:
    # use upload url you get from vk via 'video.save' call
    resp = requests.post(vk_upload_url, files={'video_file': f})

    # dumb response check
    if resp.json().get('size'):
        print('upload OK')
    else:
        print('shit happens!')

You can read about details in vk.api docs

Makc
  • 1,012
  • 12
  • 16