try to infer file type with magic bytes: if the image has e.g. content-type application/octet-stream, the file is named ...NaN,NaN... Now if the content-type is not in supported content types, the file type is detected by magic numbers (http://en.wikipedia.org/wiki/List_of_file_signatures).