我正在开发一个项目,该项目有一些跑步者,每个跑步者都可以同时上传文件。任意地我会得到一个“流不支持并发 IO 读或写操作”错误。
我们已经看到它发生在小文件(5Mb~10Mb)和大文件(1Gb~2Gb)上。我们甚至尝试了完全相同的文件,有时我们能够重现它。
我们的设置具有 NTLM 身份验证、自签名证书并使用 OWIN/Katana 自托管。全部使用 .Net 编写。
它只发生在(到目前为止)在虚拟机上,我们还没有使用物理机来解决这个问题,尽管其中一些虚拟机真的很强大
这是我的代码:
客户
public Guid Upload(string filePath, Guid taskId)
{
if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("Value cannot be empty.", "filePath"); }
var key = Guid.Empty;
var fileInfo = new System.IO.FileInfo(filePath);
using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open))
{
var content = new StreamContent(fileStream);
content.Headers.Add("TaskId", taskId.ToString());
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
content.Headers.ContentDisposition.FileName = fileInfo.Name;
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
content.Headers.ContentLength = fileInfo.Length;
key = HttpClient.PostGet<Guid>(content, "https://localhost:1234/Files/Upload");
}
return key;
}
public T …Run Code Online (Sandbox Code Playgroud)