当文件长度高于 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 = true
和AllowWriteStreamBuffering = false
但我无法正确上传文件。
提前致谢
最佳答案
也许当循环尝试将数据上传(写入)到流时,Web 服务器会发送一条错误消息(读取),指出已超出大小限制。您可以尝试使用 Wireshark 或其他网络嗅探器检查服务器和程序之间发送的内容。
关于c# - .NET Winforms c# 上传大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21879742/