Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As my review to the
C#
Microsoft.AspNet.Http.Abstractions
the IFormFile is missing the
C#
InputStream and ContentLength
in ASP.NET MVC 6, it insteads of OpenReadStream, which is not functioned to respnse to the ConvertToBytes, for example:

C#
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
C#
InputStream

and
C#
ContentLength
? In the IFormFile, are available of
C#
OpenReadStream
and
C#
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:
C#
<pre lang="C#">
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;
            
        }</pre>


What I have tried:

C#
<pre lang="C#">
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;
            
        }</pre>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900