After generating the replacement upload URL, you can now replace your video. This is done using the chunked upload method with retry handling.

The token in the upload URL is valid for four hours. This means that if the video upload takes longer than four hours to complete, an error will occur. If this happens, perform the "Get upload URL" request again to generate a new upload URL.

Chunked Upload

Sample

curl --location 'https://asset-in.video-cdn.net/chunks/env/prod/vms/<VideoManager_ID>/videos/<VIDEO_ID>?
bucketId=<BUCKET_ID>&fileId=<FILE_ID>&userId=<USERID>&__token__=<SECURITY_TOKEN>' \
--header 'Content-Type: application/octet-stream' \
--header 'Mi24-Upload-Current-Chunk: 1' \
--header 'Mi24-Upload-Total-Chunks: 1' \
--data '@/Users/<USERNAME>/Downloads/<FILE_NAME>.mp4'
URLDescription
UPLOAD_URLThe complete upload URL (see "Getting the Upload URL") from the previous step. Note that the security token must be included as a parameter.
Headers
Mi24-Upload-Total-ChunksTotal number of chunks. The example above uses 1 chunk.
Mi24-Upload-Current-Chunk

Current chunk number, starting with 1.

Content-TypeSpecify "application/octet-stream" for the content type as in the example above.
Command-line Options
--data-binary <@/FILENAME>Upload as bytes of binary data and be sure to prefix the filename with "@". Then indicate the filename (and path if necessary) of the local video file to upload.

You would need to send the above example request 1 time, incrementing the current chunk each time. You can upload your file in as many or as few chunks as you wish, although typically the chunk size should be between 2 and 10MB. By using a larger number of smaller chunks, and implementing retry handling (see next section), you can expect a smoother and more reliable upload of your videos.

Response codes

201 CREATED Successful upload of an individual chunk. The entire upload is only complete when you receive this status for all chunks. See "Retry Handling" below if you do not receive this code for an uploaded chunk.

200 OK Video chunk has already been uploaded. This response code is returned when the chunk has already been successfully uploaded.

4XX ERROR Client-side error. Response code for when the server rejects a client request due to authorization errors, authentication errors or badly-formed requests.

5XX ERROR Server-side error. Response codes for when the server was unable to process a request.

1101 If you receive this response, it means your upload was denied because you've reached the limits of your booked storage capacity

Retry Handling

If the response to a chunk upload request is not 200 OKor 201 CREATED, the chunk must be uploaded again.

This can happen for a few reasons, such as:

  • Failure in the connection across the Internet
  • Expired upload token
  • Rate-limiting
  • Timeout in receiving a response from the API

To avoid these situations interrupting your upload, we strongly suggest implementing retry handling in your code. 

A good strategy for retry handling is to wait for an incrementally longer or random time between each failure. There are several options, for example:

  • wait for 1 second, then 2, then 3 ... incrementing by one second each time
  • wait for 1 second, then 2, then 3, 5, 8, 13 ... incrementing using a Fibonacci sequence
  • wait for between 1 and 5 seconds, chosen randomly

Regardless of method, you should put a limit on the number of times you retry. Sometimes failure causes are more than transient and no amount of retries will succeed.