Upload and Retrieve the Temporary File - Flutter
This guide demonstrates how to upload and retrieve files from VideoSDK's temporary file storage system.
Both methods need a joined room. They return a Future that throws a VideoSDKError when the call fails, so await them inside try/catch. An empty argument throws 3073 (ERROR_INVALID_PARAMETER).
uploadBase64File()
-
By using the
uploadBase64File()method of theRoomclass, you can upload your file to Videosdk's Temporary storage. -
The
uploadBase64File()method only works withbase64. Therefore, it is necessary to convert your file intobase64format. -
You have to pass
base64Data,token,fileNameas parameter inuploadBase64File()function. -
The function will return the corresponding
fileUrl, which you can then use to retrieve the file. -
If the upload fails, it throws a
VideoSDKErrorwith code3074(ERROR_FILE_UPLOAD_FAILED).
Future<void> uploadFile() async {
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
try {
String? url = await room.uploadBase64File(
base64Data: base64Data,
token: token,
fileName: fileName,
);
print("fileUrl $url");
} on VideoSDKError catch (e) {
print("Upload failed: ${e.code} ${e.name}");
}
}
fetchBase64File()
-
By using the
fetchBase64File()method of theRoomclass, you can retrieve your file from Videosdk's Temporary storage. -
You have to pass the
fileUrlwhich is returned byuploadBase64File()function, and thetokenas parameters to retrieve a file. -
This function will return the image in the form of
base64. -
If the fetch fails, it throws a
VideoSDKErrorwith code3075(ERROR_FILE_FETCH_FAILED).
Future<void> fetchFile() async {
String url = "<Your FileUrl>"; //Provide fileUrl which is returned by uploadBase64File()
String token = "<VIDEOSDK_TOKEN>";
try {
String? base64 = await room.fetchBase64File(
url: url,
token: token,
);
print("base64 $base64");
} on VideoSDKError catch (e) {
print("Fetch failed: ${e.code} ${e.name}");
}
}
The file stored in the system will be automatically deleted once the current room comes to an end.
API Reference
Got a Question? Ask us on discord

