Skip to content

Sending File Name with Data Streams

Jacob Steele Sep 14, 2023 2:05:32 PM

In this blog post, we tackle a common challenge: how to send file names along with files using data streams and LiveSwitch. We provide a concise and practical guide to help you incorporate file name transmission into your data transfer process. By following the guide and utilizing code examples, you'll be able to enhance your application's functionality and streamline file management within your LiveSwitch implementation. Let's dive in and explore the solution together.

Question: How do I send the filename along with the file using data streams and LiveSwitch?

Answer: By constructing a custom frame format, we can effectively transmit both the filename and the file data.



To send the filename along with the file, we propose the following frame structure:

[size of name][end][filename][filedata]

For instance, if the file name is "myfile.jpg," you can represent it in bytes as:


myfile.jpg = 6d 79 66 69 6c 65 2e 6a 70 67 (10 bytes)
10 = 31 30

To separate the file name from the file data, use a designated separator such as "00 00 01" (e.g., for H264 enthusiasts). Combining the elements, you can send the following frame:

31 30 00 00 01 6d 79 66 69 6c 65 2e 6a 70 67 (file bytes here)

System.Text.Encoding.UTF8.GetString(new Byte[] { 6d, 79, 66, 69, 6c, 65, 2e, 6a, 70, 67 });

On the receiving end, to extract the file name:

  1. Locate the first occurrence of separator, "00 00 01."
  2. Extract everything before it and convert it to a number.
  3. Retrieve that number of bytes and convert them into a UTF-8 string, which represents the file name.
  4. Save the remaining bytes to disk as the file.

By incorporating this approach, you can effectively send the file name alongside the file using data streams and LiveSwitch. This method ensures seamless identification and processing of files on the receiving side, enhancing the overall functionality of your application. Feel free to experiment and customize the frame structure to suit your specific requirements.


Need assistance in architecting the perfect WebRTC application? Let our team help out! Get in touch with us today!