Step 1 - acquiring an upload URL
For this purpose video.getUploadUrl method must be used.
Since video must be uploaded by a certain user, you either need an access_token or session_key with VIDEO_CONTENT permission granted.
In method’s response there will be a video id and an URL which must be used to upload a video.
After you’ve finished with this step you can proceed to step 2.
Step 2 - video uploading via HTTP POST request
To upload a video you must use URL from previous step.
For example, you can upload it via curl:
Two types of an upload a supported:
- single request upload (multipart request);
- renewable upload.
This type of upload is a simpler one but it is less reliable and agile.
If a Content-Type: multipart/form-data header is passed in a request our service indicates upload type as a simple single request upload.
This type of an upload has some restrictions:
- Max. file size - 2 Gb
- Only one file per request can be uploaded
- No possibility to restart stopped / failed upload
If Content-Type header value is not equal to multipart/form-data our service indicated upload type as a renewable upload.
With a Content-Range header current file chunk range and complete file size can be passed.
If a network error has happened or upload was stopped you can continue to upload a file from the last successfully uploaded file chunk. You can request the last known byte of uploaded file from server and continue to upload a file.
Get upload status
To GET an upload status you simply need to perform HTTP-GET request to a file upload URL. Our service will respond with current upload status, complete file size and last known uploaded byte. This data can be used to complete stopped upload if something went wrong.
If REQUESTED_RANGE_NOT_SATISFIABLE or INTERNAL_SERVER_ERROR status was returned it is a good point to try to restart an upload. Возобновление загрузки имеет смысл после ошибок:
From a HTTP-response can tell what happened with an upload:
|200||OK||File was successfully uploaded|
|201||CREATED||File was partially uploaded|
|416||REQUESTED_RANGE_NOT_SATISFIABLE||Selected range was uploaded with an error|
|500||INTERNAL_SERVER_ERROR||Internal server error|
Step 3 - finishing an upload
When a file was successfully uploaded via upload url video is still not visible for users. To make it available you need to update it’s status by video.update method. After invoking this method video will be available for any user it should be available to (depending on it’s privacy settings).