I'm creating a simple controller action in ASP.NET MVC 2 (under the .NET 4.0 framework) which will resize files.
I've got a controller like this (I've cut it down a bit):
public ActionResult GetFile(int fileId, string fileSource) {
FileInfo file = repo.FindFileById(fileId);
//do some resizing
string mimeType = string.Empty;
switch(file.Extension) {
case ".jpg":
mimeType = "image/jpg";
break;
//some more stuff
default:
mimeType = "text/png";
break;
}
return File(file.FullName, mimeType);
}
On the file system it saves fine, I can view the resized file, but in the browser the file doesn't render.
I've used Charles to inspect the response and it comes back with a HTTP Status of 200, but the Image isn't visible.
If I try and save the image and view it Windows picture viewer says that it's corrupt.
I've also tried with ZIP (sans resizing ;)) and it returns a corrupt ZIP file.
I'm sure I'm just doing something wrong but I can't for the life of me spot it.
Edit
I've tested in both Cassini and IIS 7.5 (Windows 7) and recieve the problem in both instances.
I would recommend you to proceed by elimination. Start with a simple action and a working jpeg image:
If this doesn't work then you might be having some other problem (you might also try clearing the browser cache). If it works replace the
test.jpg
by the one you have but before resizing, etc, until you find the problem.