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()onRoomuploads a file to VideoSDK's temporary storage. The room must be joined. -
It takes the file as a
base64string, so convert your file tobase64first. -
Pass
base64Data,tokenandfileName. -
It is a
suspendfunction. When the upload is complete, it returns the file's URL. Pass that URL tofetchBase64File()to get the file back. -
If the upload cannot be done, it throws a
VideoSDKException:3073(ERROR_INVALID_PARAMETER) if any argument is empty.3035or3065if the room is not joined or is reconnecting. These are also reported ononError.3074(ERROR_FILE_UPLOAD_FAILED) if the upload fails. The same error is also reported ononError.
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()onRoomgets a file back from VideoSDK's temporary storage. The room must be joined. -
Pass the URL that
uploadBase64File()returned, and thetoken. -
It is a
suspendfunction. When the fetch is complete, it returns the file as abase64string. -
If the fetch cannot be done, it throws a
VideoSDKException:3073(ERROR_INVALID_PARAMETER) if any argument is empty.3035or3065if the room is not joined or is reconnecting. These are also reported ononError.3075(ERROR_FILE_FETCH_FAILED) if the fetch fails. The same error is also reported ononError.
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}")
}
}
}
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

