I am using FindMimeFromData from urlmon.dll for type MIME to nullify downloaded files. According to MIME Type Detection in Internet Explorer , image/tiff is one of the recognizable MIME types. It works fine on my development machine (Windows 7 64bit, IE9), but does not work on the test env (Windows Server 2003 R2 64bit, IE8) - it returns application/octet-stream instead of image/tiff .
The above article describes the exact steps taken to determine the MIME type, but since image/tiff is one of 26 recognized types, it must complete in step 2 (sniffing the actual data) so that file extensions and registered applications (and other registry materials) irrelevant.
Oh, and by the way, TIFF files are actually related to the program (Windows Picture and Fax Viewer) on the test server. This does not mean that TIFF links are missing from the Windows registry.
Any ideas why this is not working properly?
EDIT: FindMimeFromData is used as follows:
public class MimeUtil { [DllImport("urlmon.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = false)] private static extern int FindMimeFromData( IntPtr pBC, [MarshalAs(UnmanagedType.LPWStr)] string pwzUrl, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I1, SizeParamIndex = 3)] byte[] pBuffer, int cbSize, [MarshalAs(UnmanagedType.LPWStr)] string pwzMimeProposed, int dwMimeFlags, out IntPtr ppwzMimeOut, int dwReserved); public static string GetMimeFromData(byte[] data) { IntPtr mimetype = IntPtr.Zero; try { const int flags = 0x20;
which is then called like this:
protected void uploader_FileUploaded(object sender, FileUploadedEventArgs e) { int bsize = Math.Min(e.File.ContentLength, 256); byte[] buffer = new byte[bsize]; int nbytes = e.File.InputStream.Read(buffer, 0, bsize); if (nbytes > 0) string mime = MimeUtil.GetMimeFromData(buffer);