Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream' MVC 3
asp.net-mvc-3, c#
Solution
The stream that you get from your HTTP call is read-only sequential (non-seekable) and the FileStream is read/write seekable. You will need first to read the entire stream from the HTTP call into a byte array, then create the FileStream from that array.
Problem
I have met an issue regarding the casting type from HttpInputStream to FileStream. How I did ? I have a `HttpPostedFileBase` object and I want to have FileStream. I wrote: ``` public void Test(HttpPostedFileBase postedFile) { FileStream fileStream = (FileStream)(postedFile.InputStream); // throw exception FileStream anotherFileStream = postedFile.InputStream as FileStream; // null } ``` I tried also ``` public void Test(HttpPostedFileBase postedFile) { Stream stream = postedFile.InputStream as Stream; FileStream myFile = (FileStream)stream; } ``` But no success. Why at `postedFile.InputStream` comes `HttpInputStream` type ? And how could I solve this issue ? Thanks