Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Reply
Inputstream and contentlength is missing in microsoft.aspnet
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Sisovin CHIENG
8y
640
1
Reply
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?
Attachment:
publisherinfosrepository.rar
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
how to insert
include update information