'Net core api to upload 1GB size csv file

I have following code segment it works for small file. But if the file is larger then application is loading for long and recieves No 'Access-Control-Allow-Origin' header is present on the requested resource.

[HttpPost]
[ScopeAuthorize(Constants.ClaimScopeSGCanManageAll, Constants.ClaimScopeUserCanManage)]
[DisableRequestSizeLimit, RequestFormLimits(MultipartBodyLengthLimit = int.MaxValue, ValueLengthLimit = int.MaxValue)]
public async Task<IActionResult> UploadFile()
{

    if (!Request.Form.Files.Any())
    {
        throw new Common.Exceptions.ValidationException("Empty file");
    }

    IFormFile formFile = Request.Form.Files[0];

    var csvDatas = new List<PatientsCSVItem>();
    using (var reader = new StreamReader(formFile.OpenReadStream()))
    {
        while (!reader.EndOfStream)
        {
            var line = reader.ReadLine();
            var values = line.Split(';');

          //process csv rows
        }

    }

    PatientCsvLog executionLog = _patientCsvManager.AddOrUpdatePatientsByCsvData(csvDatas, _userManager.GetLoggedUserId(User));

    if (executionLog == null)
    {
        throw new ArgumentNullException(nameof(executionLog));
    }

    var response = new
    {
        NumberRecordImported = executionLog.NumberRecordImported,
        NumberRecordUpdated = executionLog.NumberRecordUpdated,
        NumberRecordDiscarded = executionLog.NumberRecordDiscarded,
        DiscardedRecordList = executionLog.DiscardedRecordList
    };

    return Ok(response);

}


Solution 1:[1]

If you running under the IIS try to set the maxAllowedContentLength parameter in the web.config?
The default value is approximately 28.6MB.

<?xml version="1.0" encoding="utf-8"?>
<configuration> 
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="7147483648" />
      </requestFiltering>
    </security> 
  </system.webServer>
</configuration>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1