Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Inputstream and contentlength is missing in microsoft.aspnet.http.abstractions

$
0
0

As my review to the Microsoft.AspNet.Http.Abstractions, the IFormFile is missing the InputStream and ContentLength in ASP.NET MVC 6, it insteads of OpenReadStream, which is not functioned to respnse to the ConvertToBytes, for example:

private byte[] ConvertToBytes(IFormFile image)
        {
            byte[] imageBytes = null;
            //Then, Read stream in Binary
            BinaryReader reader = new BinaryReader(image.InputStream);
            imageBytes = reader.ReadBytes((int) image.ContentLength);
            return imageBytes;
        }

Do you know what happen to InputStream and ContentLength? In the IFormFile, are available of OpenReadStream and Length. I don't know how to use it. Do anyone know how to use it. I would like to have similar code as below example:

private byte[] ConvertToBytes(IFormFile image)
        {
            byte[] imageBytes = null;
            //Then, Read stream in Binary
            BinaryReader reader = new BinaryReader(image.OpenReadStream());
            imageBytes = reader.ReadBytes((int) image.Length);
            return imageBytes;
        }

What I have tried below code, but it does't work because of BinaryReader reader = new BinaryReader(image.OpenReadStream()) show up System.NullReferenceException was unhandled by user code with HResult=-2147467261
and the Message=Object reference not set to an instance of an object.:

private byte[] ConvertToBytes(IFormFile image)
        {
            byte[] imageBytes = null;
            //Then, Read stream in Binary
            BinaryReader reader = new BinaryReader(image.OpenReadStream());
            imageBytes = reader.ReadBytes((int) image.Length);
            return imageBytes;
        }

Can you help me to resolve this problem?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>