Tutorials SignalR & Real-Time .NET Applications
Client-to-Server Streaming: Uploading in real-time
On this page
Real-time Uploads
SignalR isn't just for server-pushes. The client can also stream data to the server, useful for live video, audio, or high-frequency sensor data.
1. Streaming Interactivity
A client can call a Hub method and pass an IAsyncEnumerable as an argument. The server can then 'Consume' this stream in a foreach await loop. This allows for 'Bi-directional conversation' where both sides are streaming data simultaneously.
2. Implementation
On the Javascript client, you use a Subject to push items into the stream. On the .NET client, you can use a ChannelReader. It's a very advanced pattern that turns a standard web application into a true real-time communication platform.
3. Architect Insight
Q: "Is SignalR good for file uploads?"
Architect Answer: "Generally, NO. For standard file uploads, use an HTTP POST with multi-part form data. It's much better supported by proxies and load balancers. Reserve Client-to-Server streaming for **Continuous Data** (streaming audio, heart-rate monitors, live telemetry) where the data doesn't have a fixed 'End'."