Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the c# class StreamContent?

Tags:

c#

This is probably explained somewhere on the web but I cant find it. What exactly is a StreamContent?

(I'm trying to understand C# but I cant properly understand some WebAPi examples cos I dont understand what a StreamContent is.

A link that fully explains it (and not just list its properties etc like MSDN) would be fine.

like image 395
spiderplant0 Avatar asked Feb 04 '14 18:02

spiderplant0


1 Answers

This is an old post, but came across it so perhaps it may help others: StreamContent is a content type that can be used to set the .Content property on a HttpResponseMessage. This indicates to the web process that the content is to be streamed from a source stream (a readable stream) to the client. For example, you could open a FileStream and pass it to the constructor of StreamContent, then set that onto the .Content property. This will tell the server to read from the FileStream and stream the content down to the client, chunk by chunk. This is often preferred vs. reading the (potentially large) source stream (the file) into ram first and then returning an array (in which case the web server must use RAM to hold the file and feed it down to the client).

like image 80
otto-null Avatar answered Sep 21 '22 14:09

otto-null