Skip to main content
Version: Android SDK v1.3.0

Upload Videos

When using the VideoKit recorder, videos will be automatically uploaded as soon as you start recording. However, you are free to upload other videos through our system. The entry point is represented by the upload manager returned by VideoKit.uploads().

Note that while video upload can take some time, if the app is killed while the upload is in progress, they are automatically resumed as soon as the app is reopened. The same logic stands for connection problems.

Upload videos

To upload videos, you need to prepare the upload parameters:

// Option 1: Simple constructor
val params = UploadParams(title = "My Video")

// Option 2: Java-style builder
val params = UploadParams.builder()
.title("My Video")
.tags("My Tag")
.metadata("My Key", "My Value")
.playbackPolicy(PlaybackPolicy.Public)
.build()

// Option 3: Kotlin-friendly builder
val params = UploadParams.build {
title("My Video")
tags("My Tag")
metadata("My Key", "My Value")
playbackPolicy(PlaybackPolicy.Public)
}

Then, this object must be passed to the upload manager:

val uploads: UploadManager = VideoKit.uploads()
val upload = uploads.enqueue(videoUri, request)

Check the upload state

The enqueue() method will return an Upload object which contains useful information and data, including the Video object that is going to be saved to network.

To check the upload state, you can add an observer:

val uploads: UploadManager = VideoKit.uploads()
uploads.addObserver(object: UploadManager.Observer {
// Restrict updates to a specific upload
override fun isUploadObserved(upload: Upload): Boolean { upload.id == myUpload.id }

// Upload has started
override fun onUploadStarted(upload: Upload) { ... }

// Upload is making progress. Check the Upload object to know.
fun onUploadProgress(upload: Upload)

// Upload was completed successfully and the video should be soon available
// to other users of your app-
fun onUploadCompleted(upload: Upload, video: Video)

// Signals an unrecoverable error during the video upload.
fun onUploadError(upload: Upload, error: VideoError)
})

To query all the pending uploads, the VideoKit.uploads().uploads property will return a list of Upload objects.

Coroutines

For coroutine users, the uploadSuspending function can be used to enqueue an upload, receive start and progress events and suspend until the upload is complete. Of course, you should be ready for this function to never return, because uploads can outlive the app process.

val uploaded: Video = uploads.uploadSuspending(uri, request,
onStart = { /* started! */ },
onProgress = { /* progress! */ }
)

Cancel uploads

The upload manager provides utilities to cancel the upload for a given id, Uri or Upload:

val uploads: UploadManager = VideoKit.uploads()
uploads.cancel(video.id) // cancel by id
uploads.cancel(uri) // cancel by Uri
uploads.cancel(upload) // cancel by Upload