I need to upload and read large file (size more than 500 MB). I have a column file with datatype varbinary(MAX) in SQL Server to store.
I want to upload and read file using C#. I need to pass byte array to store file in SQL Server database. But I am getting error while initialize byte while uploading large file.
I can upload file of size 250MB. But I tried to upload file more than 500 MB, it throws "Out of Memory" exception while initializing byte array.
byte[] fileByte = new byte[file.ContentLength]; // "Out of Memory" exception
file.InputStream.Read(fileByte, 0, fileByte.Length);
I also tried
BinaryReader br = new BinaryReader(inputStream);
byte[] fileByte = br.ReadBytes(file.ContentLength); // "Out of Memory" exception
I don't want to upload and download file in chunk for file safety. Please let me know if anyone help me to upload large file OR Way to fix "Out of memory exception".
Thanks.