1

我正在尝试将图像上传到我的 IIS 7 服务器,但它已损坏。相同的代码通过 Visual Studio 在本地实例上工作。

本地标题:

Request URL:http://localhost:55272/MyProfile/UploadPhoto?qqfile=01.jpg
Request Method:POST
Status Code:302 Found
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:464542
Content-Type:application/octet-stream
Host:localhost:55272
Origin:http://localhost:55272
Referer:http://localhost:55272/MyProfile
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1130.1 Safari/536.11
X-File-Name:01.jpg
X-Mime-Type:image/jpeg
X-Requested-With:XMLHttpRequest
Query String Parametersview URL encoded
qqfile:01.jpg
Response Headersview source
Cache-Control:private
Connection:Close
Content-Length:137
Content-Type:text/html; charset=utf-8
Date:Thu, 10 May 2012 06:35:28 GMT
Location:/MyProfile/MyProfile
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0

远程标头:

Request URL:[remotehost]/XMVC/MyProfile/UploadPhoto?qqfile=01.jpg
Request Method:POST
Status Code:302 Found
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Authorization:Negotiate -snip-
Connection:keep-alive
Content-Length:464542
Content-Type:application/octet-stream
Cookie:ASPSESSIONIDAABCCDSD=-snip-
Host:[remotehost]
Origin:[remotehost]
Referer:[remotehost]/XMVC
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1130.1 Safari/536.11
X-File-Name:01.jpg
X-Mime-Type:image/jpeg
X-Requested-With:XMLHttpRequest
Query String Parametersview URL encoded
qqfile:01.jpg
Response Headersview source
Cache-Control:private
Content-Length:142
Content-Type:text/html; charset=utf-8
Date:Thu, 10 May 2012 06:35:05 GMT
Location:/XMVC/MyProfile/MyProfile
Persistent-Auth:false
Server:Microsoft-IIS/7.5
WWW-Authenticate:Negotiate -snip-
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
X-Powered-By:ASP.NET

这是上传表单调用的上传方法:

[HttpPost]
public ActionResult UploadPhoto(object qqfile)
{
    // Get current logged in user
    var currentUser = _staffRepository.StaffMembers.First(p => p.Login == User.Identity.Name.Replace("Domain\\", ""));

    var length = Request.ContentLength;
    var bytes = new byte[length];
    Request.InputStream.Read(bytes, 0, length);
    // bytes has byte content here. what do do next?

    var fileName = currentUser.Login + ".jpg";

    var saveToFileLoc = string.Format("{0}\\{1}",
                                   Server.MapPath("~/App_Data/uploads"),
                                   fileName);

    // save the file.
    var fileStream = new FileStream(saveToFileLoc, FileMode.Create, FileAccess.ReadWrite);
    fileStream.Write(bytes, 0, length);
    fileStream.Close();

    return new RedirectResult("MyProfile");
}

如果它是相关的,我正在使用这个文件上传器

图像作为所有 NUL 字节出现在远程服务器上。任何帮助表示赞赏。

4

1 回答 1

1

原来这是一个 Chrome 错误,该错误已在稳定版 19.0.1084.52(5 月 23 日发布)中修复。

具体修订:https ://src.chromium.org/viewvc/chrome?view=rev&revision=138291

详细分析:http: //inedo.com/support/kb/1019/workaround-for-chrome-file-uploading-bug

于 2012-06-06T02:57:27.337 回答