You should probably make the same change for images.  In fact, you might just be able to define a single object that maps the file name extension to the MIME type and then all the switch statements could be replaced by indexing that object.