且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从HttpPostedFile创建字节数组

更新时间:2023-11-15 18:53:58

使用一个BinaryReader对象从流像返回一个字节数组:

 字节[] FILEDATA = NULL;
使用(VAR binaryReader =新BinaryReader(Request.Files [0] .InputStream))
{
    FILEDATA = binaryReader.ReadBytes(Request.Files [0] .ContentLength);
}

Hi I'm using an image component that has a FromBinary method. Wondering how do i convert my input stream into a byte array

HttpPostedFile file = context.Request.Files[0];
byte[] buffer = new byte[file.ContentLength];
file.InputStream.Read(buffer, 0, file.ContentLength);

ImageElement image = ImageElement.FromBinary(byteArray);

Use a BinaryReader object to return a byte array from the stream like:

byte[] fileData = null;
using (var binaryReader = new BinaryReader(Request.Files[0].InputStream))
{
    fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);
}