クライアントで作成された zip ファイルを取り、ハブ ストリームを介してそのファイルをチャンクでアップロードしようとしています。ストリームが終了し、ファイルを開こうとすると、windows で開くことができない、{ファイル名} が無効であると表示されます。
File.WriteAllBytes(path, bytes[]) を実行すると、バイト配列は、チャンク化の前に、クライアントで正常に書き出されます。ストリーミング ファイルと File.WriteAllBytes を見ると、ファイル サイズは同じです。
私はアイデアがありません...
クライアント側
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;
}
}
サーバ側
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");
}
}

