Skip to main content
Version: 3.x.x

Upload and Retrieve the Temporary File - Android

Upload a file to VideoSDK's temporary storage during a room, and fetch it back by its URL.

uploadBase64File()​

  • uploadBase64File() on Room uploads a file to VideoSDK's temporary storage. The room must be joined.

  • It takes the file as a base64 string, so convert your file to base64 first.

  • Pass base64Data, token and fileName.

  • It is a suspend function. When the upload is complete, it returns the file's URL. Pass that URL to fetchBase64File() to get the file back.

  • If the upload cannot be done, it throws a VideoSDKException:

    • 3073 (ERROR_INVALID_PARAMETER) if any argument is empty.
    • 3035 or 3065 if the room is not joined or is reconnecting. These are also reported on onError.
    • 3074 (ERROR_FILE_UPLOAD_FAILED) if the upload fails. The same error is also reported on onError.
private fun uploadFile() {
val base64Data = "<Your File's base64>" // Convert your file to base64 and pass here
val token = "<VIDEOSDK_TOKEN>"
val fileName = "myImage.jpeg" // Provide name with extension here
lifecycleScope.launch {
try {
val fileUrl = room!!.uploadBase64File(base64Data, token, fileName)
Log.d("VideoSDK", "Uploaded file url: $fileUrl")
} catch (e: VideoSDKException) {
Log.d("VideoSDK", "Error in upload file: ${e.code} ${e.message}")
}
}
}

fetchBase64File()​

  • fetchBase64File() on Room gets a file back from VideoSDK's temporary storage. The room must be joined.

  • Pass the URL that uploadBase64File() returned, and the token.

  • It is a suspend function. When the fetch is complete, it returns the file as a base64 string.

  • If the fetch cannot be done, it throws a VideoSDKException:

    • 3073 (ERROR_INVALID_PARAMETER) if any argument is empty.
    • 3035 or 3065 if the room is not joined or is reconnecting. These are also reported on onError.
    • 3075 (ERROR_FILE_FETCH_FAILED) if the fetch fails. The same error is also reported on onError.
private fun fetchFile() {
val url = "<Your FileUrl>" // Provide fileUrl which is returned by uploadBase64File()
val token = "<VIDEOSDK_TOKEN>"
lifecycleScope.launch {
try {
val base64Data = room!!.fetchBase64File(url, token)
Log.d("VideoSDK", "Fetched file in base64:$base64Data")
} catch (e: VideoSDKException) {
Log.d("VideoSDK", "Error in fetch file: ${e.code} ${e.message}")
}
}
}
note

The file is deleted automatically when the room ends.

API Reference​

The API references for all the methods and events utilised in this guide are provided below.

Got a Question? Ask us on discord