File upload Request.Files[0]。InputStream在上载后显示不同的长度

File upload Request.Files[0]。InputStream在上载后显示不同的长度,file-upload,md5,httprequest,inputstream,File Upload,Md5,Httprequest,Inputstream,当用户将该文件上传到我的服务器时,我试图创建该文件的MD5,并将该请求连同已发布的文件一起转发到我的服务,该服务使用以下方法重新检查已发布文件的MD5 这始终显示服务端上Request.Files[0].InputStream的不同长度。是否有什么我遗漏了,为什么这会显示不正确的长度为张贴的文件 if (context.Request.Files.Count > 0) { byte[] fileData = null; usi

当用户将该文件上传到我的服务器时,我试图创建该文件的MD5,并将该请求连同已发布的文件一起转发到我的服务,该服务使用以下方法重新检查已发布文件的MD5

这始终显示服务端上Request.Files[0].InputStream的不同长度。是否有什么我遗漏了,为什么这会显示不正确的长度为张贴的文件

if (context.Request.Files.Count > 0)
        {
            byte[] fileData = null;
            using (var binaryReader = new BinaryReader(context.Request.Files[0].InputStream))
            {
                fileData = binaryReader.ReadBytes((int)context.Request.Files[0].InputStream.Length);
                binaryReader.Close();
            }

            using (MD5 md5 = MD5.Create())
            {
                byte[] hashData = md5.ComputeHash(fileData);

                //loop for each byte and add it to StringBuilder
                for (int i = 0; i < hashData.Length; i++)
                {
                    FileMD5Hash.Append(hashData[i].ToString());
                }
            }
        }
if(context.Request.Files.Count>0)
{
字节[]fileData=null;
使用(var binaryReader=new binaryReader(context.Request.Files[0].InputStream))
{
fileData=binaryReader.ReadBytes((int)context.Request.Files[0].InputStream.Length);
binaryReader.Close();
}
使用(MD5 MD5=MD5.Create())
{
byte[]hashData=md5.ComputeHash(fileData);
//循环每个字节并将其添加到StringBuilder
for(int i=0;i
这不是创建字节[]的正确方法。我用了memorystream的toArray(),它对我来说工作得很好