You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Blazor to upload files. This version of my upload method fails:
public async Task UploadFail(IBrowserFile file)
{
using var db = await _dbFactory.GetDatabase();
var stream = file.OpenReadStream(file.Size);
await db.FileStorage.UploadAsync("test", file.Name, stream);
}
The call stack is (trimmed):
LiteDB.Async.LiteAsyncException: LiteDb encounter an error. Details in the inner exception.
---> System.NotSupportedException: Synchronous reads are not supported.
at Microsoft.AspNetCore.Components.Forms.BrowserFileStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize)
at LiteDB.LiteStorage`1.Upload(TFileId id, String filename, Stream stream, BsonDocument metadata)
at LiteDB.Async.LiteStorageAsync`1.<>c__DisplayClass11_0.<UploadAsync>b__0()
at LiteDB.Async.LiteDatabaseAsync.<>c__DisplayClass36_0`1.<EnqueueAsync>g__Function|0()
If I change it to use an intermediary MemoryStream it works, but I have a feeling that this would buffer the entire file into memory a second time. Here's my workaround though:
var stream = new MemoryStream();
await file.OpenReadStream(file.Size).CopyToAsync(stream);
stream.Seek(0, SeekOrigin.Begin);
await db.FileStorage.UploadAsync(image.Id.ToString(), image.Filename, stream);
The text was updated successfully, but these errors were encountered:
I'm using Blazor to upload files. This version of my upload method fails:
The call stack is (trimmed):
If I change it to use an intermediary
MemoryStream
it works, but I have a feeling that this would buffer the entire file into memory a second time. Here's my workaround though:The text was updated successfully, but these errors were encountered: