我们正在使用asp.net的Asyncfileupload控件来上传文件,同样是不工作的,我们已经调试并发现了以下代码:
input.Read(buffer, 0, buffer.Length)
返回0。
整个代码是这样的:
public static byte[] ReadFully(Stream input)
{
byte[] buffer = new byte[input.Length];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
流。如果您处于字节数组的末尾或网络连接中断,Read可能返回0。您可以尝试这行代码来确保:
byte[] buffer = new byte[input.Length];
input.Position=0;
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}