9
Follows code:
Controller (with post action):
var file = Request.Files[0];
var bytes = ConvertTo.Bytes(file);
Convertto class :
public static byte[] Bytes(HttpPostedFileBase result)
{
var length = result.InputStream.Length; //Length: 103050706
MemoryStream target = new MemoryStream();
result.InputStream.CopyTo(target); // gera problema nessa linha aqui
byte[] data = target.ToArray();
return data;
}
The file is about 98.2 MB (103,050,706 bytes) in size, 60 MB file works perfectly.
On the line: result.InputStream.CopyTo(target);
get error:
System.Outofmemoryexception: 'Exception_wasthrown'
Small file works well, only big file makes this problem.
Any solution for large file ?
UPDATE:
Follows code:
public static byte[] ConverToBytes(HttpPostedFileBase file)
{
var length = file.InputStream.Length; //Length: 103050706
byte[] fileData = null;
using (var binaryReader = new BinaryReader(file.InputStream))
{
fileData = binaryReader.ReadBytes(file.ContentLength);
}
return fileData;
}
Code above works using BinaryReader
. Because MemoryStream
doesn’t work ?
Matheus, what are the versions of IIS, . NET Runtime and the operating environment you are using? 32 or 64 bit?
– OnoSendai
@Onosendai 10.0.16299.15 and Windows 10. It is 64 bits, In the project is as 32 bits.
– Matheus Miranda