0

I found this question while struggling: Is it OK to pass a stream around to multiple methods?. The general consensus is that it is OK as long as the stream is guarded and any new consumer of the stream reset their position to zero.

My scenario is retrieving a file from an API and then ultimately streaming that file as a download through an ASP.NET controller. How would the stream be cleared if it's just passed as a the response?

Community
  • 1
  • 1
brendon.otto
  • 44
  • 1
  • 8
  • Web API? Or MVC? –  Jan 31 '17 at 23:08
  • I'm using a WebAPI controller – brendon.otto Feb 01 '17 at 04:24
  • See the comments on the first answer. –  Feb 01 '17 at 13:36
  • I read the comments and it helped clarify some portions of what I was looking to do. My particular issue is an API is returning a stream in response to a call and I would like to skip writing the returned stream to a local file. I therefore arrived at passing the stream as the return of the method receiving the API call and then rendering that back from the controller to the client. That question goes into opening a file and returning it to a client but not with the source being a stream. It did help clarify things so I will accept it as solving the problem. – brendon.otto Feb 01 '17 at 16:59
  • Where the stream originates and how it was created are irrelevant. A stream is a stream, and you have one and want to return its contents to the API caller. It isn't necessary to write the stream to a local file if you don't want to. Just return a `FileStreamResult`. –  Feb 01 '17 at 17:05
  • Thank you, I was making it harder than I need to! – brendon.otto Feb 01 '17 at 17:55

0 Answers0