I am attempting to upload an image to my IIS 7 server, but it is coming out corrupted. The same code works on a local instance through Visual Studio.
Local headers:
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
Remote headers:
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
Here is my upload method that is called by the upload form:
[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");
}
If it is relevant I am using this File Uploader
The image comes out on the remote server as all NUL bytes. Any assistance is appreciated.
Turns out this was a Chrome bug that has since been fixed in stable 19.0.1084.52 (released 23rd May).
Specific revision: https://src.chromium.org/viewvc/chrome?view=rev&revision=138291
Detailed analysis: http://inedo.com/support/kb/1019/workaround-for-chrome-file-uploading-bug