Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a FileContentResult to a FileStreamResult?

I have a FileContentResult obtained from a byte array and want to turn it into a FileStreamResult. Is this possible? If so, how?

like image 871
SantLev Avatar asked Dec 04 '25 13:12

SantLev


1 Answers

Firstly, I don't know much about MVC but it sounds like you shouldn't need to do this. If you have code which depends on FileStreamResult, see if you could make it depend on FileResult instead, which is the base class of both FileStreamResult and FileContentResult.

But otherwise, you could always use:

var streamResult = new FileStreamResult(new MemoryStream(contentResult.FileContents),
                                        contentResult.ContentType)
streamResult.FileDownloadName = contentResult.FileDownloadName;
// You could use an object initializer instead of a separate statement, of course.
like image 63
Jon Skeet Avatar answered Dec 07 '25 03:12

Jon Skeet