robinrodricks / FluentStorage

A polycloud .NET cloud storage abstraction layer. Provides Blob storage (AWS S3, GCP, FTP, SFTP, Azure Blob/File/Event Hub/Data Lake) and Messaging (AWS SQS, Azure Queue/ServiceBus). Supports .NET 5+ and .NET Standard 2.0+. Pure C#.
MIT License
263 stars 33 forks source link

Make Disk WriteAsync also use CopyToAsync #50

Closed timbze closed 7 months ago

timbze commented 8 months ago

Fixes

System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.EnsureBuffered(Int32 minCount)
   at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize)
   at FluentStorage.Blobs.Files.DiskDirectoryBlobStorage.WriteAsync(String fullPath, Stream dataStream, Boolean append, CancellationToken cancellationToken)

Note

I also think this fix is the correct way to handle this. Reading synchronously in a async method does not seem like the right way to do it if async is available, and it is available here.

robinrodricks commented 7 months ago

Thanks for this.

timbze commented 7 months ago

@robinrodricks do you have a plan on when you will release this to nuget?

robinrodricks commented 7 months ago

Released!

https://www.nuget.org/packages/FluentStorage/5.4.2