简体   繁体   English

.NET Winforms c# 上传大文件

[英].NET Winforms c# Upload large files

I get this error when file length is higher than 18 mb:当文件长度高于 18 mb 时出现此错误:

stream does not support concurrent IO read or write operations stream 不支持并发 IO 读写操作

The error is localized in this section:该错误已本地化在本节中:

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();

I tried with lock sentence, sendChunked = true and AllowWriteStreamBuffering = false But I can't upload files correctly.我尝试使用lock语句, sendChunked = trueAllowWriteStreamBuffering = false但我无法正确上传文件。

Thanks in advance提前致谢

Maybe the web server sends an error message (read) that the size limit has exceeded while the loop tries to upload (write) data to the stream. 在循环尝试将数据上传(写入)到流时,Web服务器可能发送了一条错误消息(读取),该消息超出了大小限制。 You can try to check what is sent between the server and the program with Wireshark or some other network sniffer. 您可以尝试使用Wireshark或其他网络嗅探器检查服务器与程序之间发送的内容。

Web servers have some limits. Web 服务器有一些限制。 You should set these limits so that not exceeded.您应该设置这些限制,以免超出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM