I have an endpoint in swagger UI where I upload a .txt file and looks like this:
[HttpPost("UploadBlackList")]
public IActionResult UploadBlackList(IFormFile formFile)
{
try
{
Task.Run(async () =>
{
using Proceso proceso = new Proceso(_log, _datos, _storage, _gdp, _client, _apiIag, _proxy);
await proceso.UploadBlackList(formFile);
});
return Accepted();
}
catch (Exception err)
{
_log.LogError(err.Message);
return BadRequest();
}
}
After that is there the function:
await proceso.UploadBlackList(formFile);
Here I have the processing part of the file but when I try to read the file:
public async Task UploadBlackList(IFormFile formFile)
{
using var tabla = new Tabla(_log, _storage);
var lines = new List<string>();
try
{
using (var stream = formFile.OpenReadStream())
using (var reader = new StreamReader(stream))
{
while (reader.Peek() >= 0)
{
var line = await reader.ReadLineAsync();
var sinleer = new SinLeer
{
PartitionKey = _partitionKey,
RowKey = Guid.NewGuid().ToString(),
Estado = line
};
}
}
}
catch (Exception ex)
{
_log.LogError($"Internal server error: {ex.Message}");
}
}
Here when I call the OpenReadStream() I get this error:
System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'System.String'.'
What am I doing wrong here ?
I tried to run with .copytoasync but is the same problem as in this case.
New contributor
Catalin Briscan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.