OutOfMemoryException when uploading a file to the database

I have an application MVCthat requires me to upload a data file to it. The need for a data file is to update records in our database.

The problem is that when I try to read a file to save to the database, I get OutOfMemoryException. Download file size 186MB. I worked out in a smaller file, roughly 120MB.

It throws an exception in the line of code CopyTo. However, I tried to use BinaryReaderand even save the file on the server and read it, and none of the ways changed the situation. The same one exceptiongets thrown. My controller action:

public ActionResult UpdateAddresses(HttpPostedFileBase addressFile)
{
    using (var addressStream = new MemoryStream())
    {
        addressFile.InputStream.CopyTo(addressStream);
        var addressFileName = addressFile.FileName;
        addressFile = null;

        documentService.AddDocument(DateTime.Now, addressFile.FileName, FileTypes.ProducerAddressUpdate, addressStream.ToArray(), this.CurrentUser.AccountName);
    }

    return Index();
}

strea m. , out of memory exception, byte[]. byte array .NET . , . , .

+4

Source: https://habr.com/ru/post/1608750/


All Articles