Hello, we are using IRemoteStreamContent to upload images in our solution. let's say we have a DTO called A identified like so:
public record A {
public string Name {get; init;}
public B Bs {get; init;}
public List <IRemoteStreamContent> Images {get; init} = [];
}
Let's say we have an Application Service named TestApplicationService. In this service, I'm calling a Custom Blob Service that uploads Azure blob images.
public class TestAppService : AppService {
public Task<bool> CreateRecordA(A dto)
{
foreach(var image in dto.Images)
{
await blobService.SaveBlobAsync(image);
}
return true;
}
}
as for the Custom blob Service I will expose the method as follows:
public async Task<bool> SaveBlobAsync(IRemoteStreamContent file, CancellationToken cancellationToken = default)
{
using var memoryStream = new MemoryStream();
await file.GetStream().CopyToAsync(memoryStream, cancellationToken);
var fileContent = memoryStream.ToArray();
await memoryStream.FlushAsync(cancellationToken);
await blobContainer.SaveAsync(CleanFileName(file.FileName!), fileContent, true, cancellationToken);
return true;
}
In our host module we added this line in conventional controllers:
Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.FormBodyBindingIgnoredTypes.Add(typeof(A));
options.ConventionalControllers.Create(typeof(TestApplicationModule).Assembly);
});
The problem is that whenever I have more than 1 image in my dto we are facing an exception of HTTP stream positioning changed unexpectedly, noting that we followed step by step https://abp.io/docs/latest/framework/architecture/domain-driven-design/application-services#miscellaneous
System.InvalidOperationException: The inner stream position has changed unexpectedly.
at Microsoft.AspNetCore.Http.ReferenceReadStream.VerifyPosition()
at Microsoft.AspNetCore.Http.ReferenceReadStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)
at System.IO.Stream.<CopyToAsync>g__Core|27_0(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
at Totssy_Backend.BuildingBlocks.Services.Blob.BlobService.SaveBlobAsync(IRemoteStreamContent file, CancellationToken cancellationToken) in C:\Repos\Lykos\Totssy-Backend\src\Totssy_Backend.BuildingBlocks\Services\Blob\BlobService.cs:line 80
at StockManager.Services.Catalog.CatalogsAppService.PostProductAsync(CreateProductDto productDto)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)