How to decouple application service from IFormFile without stream copy overhead in asp.net core.
public interface IUploadService
{
Task UploadAsync(IFormFile file, CancellationToken cancellationToken = default);
}
[HttpPost]
public async Task<IActionResult> UploadFile([FromServices] IUploadService uploadService)
{
foreach(var file in Request.Form.Files)
{
await uploadService.UploadAsync(file);
}
return Ok();
}
I need to decouple UploadAsync method from IFormFile, because application service layer depend on Microsoft.AspNetCore.Http.Features package and I should remove it. A solution is to copy IFormFile to file stream or memory stream and pass stream to UploadAsync method. but this way has stream copy overhead. I need to solution that has not any overhead and decouple application service from IFormFile. for example any way to pass pointer of IFormFile stream and copy stream in UploadAsync method. Thanks.