Posts
48
Comments
143
Trackbacks
0
May 2011 Entries
WebImage.GetImageFromRequest() returns null

TL;DR: The WebImage.GetImageFromRequest() is case-sensitive with regard to the extensions of the image file names. More info here: http://forums.asp.net/t/1682158.aspx/1

Lately I’ve been working on a little side project in my spare time that requires that I allow users to upload an image from their computer. I’ve been using ASP .NET MVC 3 with Razor views and have been having a great time with it so far.

I was excited to find the microsoft-web-helpers package on NuGet, as it contains what appeared to be a really useful helper class called ‘WebImage’ for easily accepting uploaded images and performing simple manipulation like resizing and cropping. I was happily using this little library for awhile before discovering that is has a few pretty significant issues. First of all, the resize functionality completely breaks under certain circumstances, but that issue is beyond the scope of this post. The issue that really put the breaks on my momentum was much more fundamental: the ‘GetImageFromRequest’ method, which is used for grabbing an image from the POSTed form data, was returning ‘null’ for seemingly valid images.

I had the basic functionality of this little application more or less done and had been testing it locally my own computer without issue, but had also recruited some friends and family to try it out as well. I was getting really odd reports that it wasn’t working for some pictures that were taken on a digital camera. This was really puzzling and I spent hours pouring over the properties of the jpeg files that were failing, but couldn’t find any smoking gun.

Today I finally did what I should have done days ago and did a little Googling to see if this was a known issue. Within a couple of minutes I had found a post on the ASP .NET forums that explained the issue: the ‘GetImageFromRequest’ method has problems if the extension of the image file name is capitalized (e.g. ‘GIF’ instead of ‘gif’). When the images were being saved to the computer from the digital camera they were coming across with .JPG extensions, which was causing the issue. Thankfully there are a couple of good suggestions on that forum post with good workarounds. I ended up creating a substitute ‘GetImageFromRequest’ method as advocated in one of the responses which seems to be working great so far.

I’ve been a bit disappointed in the WebImage helper class. These issues I’ve encountered really prevent me from using it in the way I wanted to and, in my opinion, make it unusable for any “real” application. I really hope that these issues get addressed in a future version.

Posted On Monday, May 30, 2011 1:51 PM | Comments (4)
Meta
Tag Cloud