gpt4 book ai didi

c# - .NET Winforms c# 上传大文件

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:34 24 4
gpt4 key购买 nike

当文件长度大于 18 mb 时,我会收到此错误:

stream does not support concurrent IO read or write operations

错误定位于此部分:

requestStream.Write(header, 0, header.Length);
if (fileData != null)
{
// write the file data, if any
byte[] buffer = new Byte[checked((uint)Math.Min(8192, (int)fileData.Length))];
int bytesRead;

try
{
while ((bytesRead = fileData.Read(buffer, 0, buffer.Length)) != 0)
{
//throws an exception after 3000 loops aprox
requestStream.Write(buffer, 0, bytesRead);
}
}
catch (Exception ex)
{
string aux = ex.Message;
}
}

// write footer
requestStream.Write(footer, 0, footer.Length);
return webrequest.GetResponse();

我尝试使用lock 语句,sendChunked = trueAllowWriteStreamBuffering = false 但我无法正确上传文件。

提前致谢

最佳答案

也许当循环尝试将数据上传(写入)到流中时,Web 服务器发送一条错误消息(读取)表明已超出大小限制。您可以尝试使用 Wireshark 或其他网络嗅探器检查服务器和程序之间发送的内容。

关于c# - .NET Winforms c# 上传大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21879742/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com