2012-05-10 53 views
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"); 
} 

如果是相关的,我使用这个File Uploader

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

+0

这似乎这是使用Chrome 20开发浏览器有问题。最新的Firefox和IE 9似乎这样做很好。我正在进一步调查。 – joshschreuder

回答