does livekit sdk swift have send file
# ask-ai
n
does livekit sdk swift have send file
t
Thanks for reaching out, rohit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to let you know that the LiveKit Swift SDK does support sending files using its byte stream functionality. You can use the
sendFile(_:for:)
method to send a file stored on disk to participants in a room. This method needs a
fileURL
(which is the file's location) and a
topic
parameter to make sure the stream is routed to the right handlers. If you want a bit more control, the
sendFile(_:options:)
method is a great option. It lets you send files with custom options, like specifying destination participants or adding metadata. When the file is sent successfully, it returns a
ByteStreamInfo
object with helpful details such as the file’s name, MIME type, total size, and a unique stream ID. Here’s a simple example to get you started:
Copy code
let fileURL = URL(filePath: "/path/to/file.pdf")

do {
    let streamInfo = try await localParticipant.sendFile(fileURL, for: "documents")
    print("File sent: \(streamInfo.name), Size: \(streamInfo.totalLength) bytes")
} catch {
    print("Failed to send file: \(error.localizedDescription)")
}
To receive files, participants just need to register a byte stream handler for the topic using
registerByteStreamHandler(for:)
on the room instance. If you have any questions or need a hand with this, please don’t hesitate to ask—I’m here to help! Sources: .github/workflows/ci.yaml | Sending files & bytes | LiveKit Docs | Realtime data | LiveKit Docs | Web and mobile frontends | LiveKit Docs