mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-15 03:54:14 +01:00
fixes for file uploads
This commit is contained in:
parent
bff6a3dca5
commit
3a6c9259a0
4 changed files with 36 additions and 15 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue