Skip to main content
Version: 4.x.x

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 the Room class, you can upload your file to VideoSDK's temporary storage.

  • The uploadBase64File() function only works with base64 String. Therefore, it is necessary to convert your file into base64 String format.

  • You have to pass base64Data,token,fileName as parameter in uploadBase64File() function.

  • The function is async throws, so call it with try await. It will return the corresponding url, which you can then use to retrieve the file.

  • If the upload fails, it will throw a VideoSDKError:

    • ERROR_INVALID_PARAMETER if base64Data, token or fileName is empty.
    • ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED if you have not joined the room, or ERROR_ROOM_RECONNECTING while the room is reconnecting.
    • ERROR_FILE_UPLOAD_FAILED if the upload request fails.

    Except for ERROR_INVALID_PARAMETER, these errors are also sent to onError(error:).

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 the Room class, you can retrieve your file from VideoSDK's temporary storage.

  • You have to pass the url which is returned by uploadBase64File() function, and the token as parameters to retrieve a file.

  • This method is async throws. It will return the file in the form of base64 String.

  • If the retrieval fails, it will throw a VideoSDKError:

    • ERROR_INVALID_PARAMETER if url or token is empty.
    • ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED if you have not joined the room, or ERROR_ROOM_RECONNECTING while the room is reconnecting.
    • ERROR_FILE_FETCH_FAILED if the fetch request fails.

    Except for ERROR_INVALID_PARAMETER, these errors are also sent to onError(error:).

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)")
}
}
}
note

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