Upload and Retrieve the Temporary File - iOS
This guide demonstrates how to upload and retrieve files from VideoSDK's temporary file storage system.
uploadBase64File()
-
By using the
uploadBase64File()function of theRoomclass, you can upload your file to VideoSDK's temporary storage. -
The
uploadBase64File()function only works withbase64String. Therefore, it is necessary to convert your file intobase64String format. -
You have to pass
base64Data,token,fileNameas parameter inuploadBase64File()function. -
The function is
async throws, so call it withtry await. It will return the correspondingurl, which you can then use to retrieve the file. -
If the upload fails, it will throw a
VideoSDKError:ERROR_INVALID_PARAMETERifbase64Data,tokenorfileNameis empty.ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINEDif you have not joined the room, orERROR_ROOM_RECONNECTINGwhile the room is reconnecting.ERROR_FILE_UPLOAD_FAILEDif the upload request fails.
Except for
ERROR_INVALID_PARAMETER, these errors are also sent toonError(error:).
- Swift
func uploadFile() {
let base64Data: String = "<Your-base64-File>"
let token: String = "<Your-Token>"
let fileName: String = "name.jpeg" // Provide file name with extension
Task {
do {
let url = try await room?.uploadBase64File(base64Data: base64Data, token: token, fileName: fileName)
print("url: ", url ?? "")
} catch {
print("upload failed: \(error)")
}
}
}
fetchBase64File()
-
By using the
fetchBase64File()function of theRoomclass, you can retrieve your file from VideoSDK's temporary storage. -
You have to pass the
urlwhich is returned byuploadBase64File()function, and thetokenas parameters to retrieve a file. -
This method is
async throws. It will return the file in the form ofbase64String. -
If the retrieval fails, it will throw a
VideoSDKError:ERROR_INVALID_PARAMETERifurlortokenis empty.ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINEDif you have not joined the room, orERROR_ROOM_RECONNECTINGwhile the room is reconnecting.ERROR_FILE_FETCH_FAILEDif the fetch request fails.
Except for
ERROR_INVALID_PARAMETER, these errors are also sent toonError(error:).
- Swift
func fetchFile() {
let url: String = "<Your FileUrl>" // Provide fileUrl which is returned by uploadBase64File()
let token: String = "<Your-Token>"
Task {
do {
let base64Data = try await room?.fetchBase64File(url: url, token: token)
print("base64: ", base64Data ?? "")
} catch {
print("retrieval failed: \(error)")
}
}
}
The file stored in the system will be automatically deleted once the current room comes to an end.
Got a Question? Ask us on discord

