Upload and Retrieve the Temporary File - Android
This guide demonstrates how to upload and retrieve files from VideoSDK's temporary file storage system.
uploadBase64File()
-
By using the
uploadBase64File()
method of theMeeting
class, you can upload your file to Videosdk's Temporary storage. -
The
uploadBase64File()
method only works withbase64
. Therefore, it is necessary to convert your file intobase64
format. -
You have to pass
base64Data
,token
,fileName
and implementation ofTaskCompletionListener
as parameter inuploadBase64File()
method. -
When the upload is complete, the
onComplete()
method ofTaskCompletionListener
will provide the correspondingfileUrl
, which can be used to retrieve the uploaded file. -
If an error occurs during the upload process, the
onError()
method ofTaskCompletionListener
will provide the error details.
- Kotlin
- Java
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
meeting!!.uploadBase64File(
base64Data,
token,
fileName,
object : TaskCompletionListener<String?, String?> {
override fun onComplete(data: String?) {
Log.d("VideoSDK", "Uploaded file url: $data")
}
override fun onError(error: String?) {
Log.d("VideoSDK", "Error in upload file: $error")
}
}
)
}
private void uploadFile() {
String base64Data = "<Your File's base64>"; // Convert your file to base64 and pass here
String token = "<VIDEOSDK_TOKEN>";
String fileName = "myImage.jpeg"; // Provide name with extension here
meeting.uploadBase64File(base64Data, token, fileName, new TaskCompletionListener<String, String>() {
@Override
public void onComplete(@Nullable String data) {
Log.d("VideoSDK", "Uploaded file url: " + data);
}
@Override
public void onError(@Nullable String error) {
Log.d("VideoSDK", "Error in upload file: " + error);
}
});
}
fetchBase64File()
-
By using the
fetchBase64File()
method of theMeeting
class, you can retrieve your file from Videosdk's Temporary storage. -
To retrieve a file, you need to pass the
fileUrl
(which is returned by theuploadBase64File()
method), thetoken
, and an implementation of theTaskCompletionListener
as parameters. -
When the fetch operation is complete, the
onComplete()
method ofTaskCompletionListener
will provide the file inbase64
format. -
If an error occurs during the fetch operation, the
onError()
method ofTaskCompletionListener
will provide the error details.
- Kotlin
- Java
private fun fetchFile() {
val url = "<Your FileUrl>" // Provide fileUrl which is returned by uploadBase64File()
val token = "<VIDEOSDK_TOKEN>"
meeting.fetchBase64File(url, token, object : TaskCompletionListener<String?, String?> {
override fun onComplete(data: String?) {
Log.d("VideoSDK", "Fetched file in base64:$data")
}
override fun onError(error: String?) {
Log.d("VideoSDK", "Error in fetch file: $error")
}
})
}
private void fetchFile() {
String url = "<Your FileUrl>"; // Provide fileUrl which is returned by uploadBase64File()
String token = "<VIDEOSDK_TOKEN>";
meeting.fetchBase64File(url, token, new TaskCompletionListener<String, String>() {
@Override
public void onComplete(@Nullable String data) {
Log.d("VideoSDK", "Fetched file in base64:" + data);
}
@Override
public void onError(@Nullable String error) {
Log.d("VideoSDK", "Error in fetch file: " + error);
}
});
}
The file stored in the system will be automatically deleted once the current room/meeting comes to an end.
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