I'm attempting to take a zip file created on the client, and upload that file in chunks via a Hub stream. When the stream ends, and I try to open the file, windows states it can't open, {file name} is invalid.
The byte array, prior to chunking, writes out fine on the client when doing a File.WriteAllBytes(path, bytes[]). File sizes are identical when looking at the streamed file, and the File.WriteAllBytes.
I'm out of ideas...
Client side
private async IAsyncEnumerable<byte[]> StreamBytes(byte[] bytes)
{
//this works and I'm able to open the file it creates.
File.WriteAllBytes(@"C:\test.zip", bytes);
long fileSize = bytes.Length;
long fileWrite = 0;
while (fileSize != 0)
{
byte[] buffer = fileSize > ByteHelper.BUFFER_SIZE ? new byte[ByteHelper.BUFFER_SIZE] : new byte[fileSize];
Array.Copy(bytes, buffer, buffer.Length);
fileSize -= buffer.Length;
fileWrite += buffer.Length;
var bufResult = await Task.FromResult(buffer);
yield return bufResult;
}
}
Server Side
public async Task UploadCommandResultStream(IAsyncEnumerable<byte[]> byteChunk, int commandQueueKey, string folder)
{
var path = Path.Combine(_settings.UploadPath, folder);
if (Directory.Exists(path) == false)
{
Directory.CreateDirectory(path);
}
var file = Path.Combine(path, $"{commandQueueKey}.zip");
long bytesread = 0;
try
{
//this creates a file but can't open
using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read, ByteHelper.BUFFER_SIZE))
{
await foreach (var bytes in byteChunk)
{
fs.Write(bytes, 0, bytes.Length);
bytesread += bytes.Length;
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "asyncwrite");
}
}

