fixes for file uploads

This commit is contained in:
Stanley Dimant
2022-08-27 01:13:49 +02:00
parent bff6a3dca5
commit 3a6c9259a0
4 changed files with 36 additions and 15 deletions

View File

@@ -206,16 +206,25 @@ namespace MareSynchronosServer.Hubs
return;
}
UploadFileRequest req = new();
req.FileData = ByteString.CopyFrom(await File.ReadAllBytesAsync(tempFileName).ConfigureAwait(false));
File.Delete(tempFileName);
req.Hash = computedHashString;
req.Uploader = AuthenticatedUserId;
Metadata headers = new Metadata()
{
{ "Authorization", Context.User!.Claims.SingleOrDefault(c => c.Type == ClaimTypes.Authentication)?.Value }
};
_ = await _fileServiceClient.UploadFileAsync(req, headers).ConfigureAwait(false);
var streamingCall = _fileServiceClient.UploadFile(headers);
using var tempFileStream = new FileStream(tempFileName, FileMode.Open, FileAccess.Read);
int size = 1024 * 1024;
byte[] data = new byte[size];
int readBytes;
while ((readBytes = tempFileStream.Read(data, 0, size)) > 0)
{
await streamingCall.RequestStream.WriteAsync(new UploadFileRequest()
{
FileData = ByteString.CopyFrom(data, 0, readBytes),
Hash = computedHashString,
Uploader = AuthenticatedUserId
}).ConfigureAwait(false);
}
await streamingCall.RequestStream.CompleteAsync();
}
catch (Exception ex)
{