HTML 5 (video) IMediaFile MimeType incorrect

Topics: Troubleshooting
Jul 27, 2011 at 1:24 PM
Edited Jul 27, 2011 at 1:41 PM

Hi,

The default MimeType passed on by a processed IMediaFile (i.e. from the media library through ShowMedia.ashx) for video and audio (did not test them all) is incorrect.
In most cases it is returned as 'application/octet-stream' but browsers require more specific mimetypes to process correctly.

The 'HTML5BoilerPlate' way, i.e. set the correct mimetypes in the web.config is totally ignored.
A work-around (that works for me) is to modify the showmedia.ashx ValidateAndSend method:

Replace the line (84 in my case - latest version): context.Response.ContentType = file.MimeType;

with:

// Get the lowercase name to match and correct MimeTypes for audio & video stuff        string lowerCaseFileName = file.FileName.ToLower();        // We match it on the file extension        if (lowerCaseFileName.EndsWith("mp3"))        {            context.Response.ContentType = "audio/mpeg";        }        else if (lowerCaseFileName.EndsWith("mp4"))        {            context.Response.ContentType = "video/mp4";        }        else if (lowerCaseFileName.EndsWith("ogg"))        {            context.Response.ContentType = "audio/ogg";        }        else if (lowerCaseFileName.EndsWith("ogv"))        {            context.Response.ContentType = "video/ogg";        }        else if (lowerCaseFileName.EndsWith("webm"))        {            context.Response.ContentType = "video/webm";        }        else if (lowerCaseFileName.EndsWith("svg"))        {            context.Response.ContentType = "image/svg+xml";        }        else if (lowerCaseFileName.EndsWith("svgz"))        {            context.Response.ContentType = "image/svg+xml";        }        else if (lowerCaseFileName.EndsWith("flv"))        {            context.Response.ContentType = "video/x-flv";        }        else if (lowerCaseFileName.EndsWith("flv4"))        {            context.Response.ContentType = "video/mp4";        }         else        {            // Use the default            context.Response.ContentType = file.MimeType;        }

Just copy and paste (VS will serve correct identation).

Hope this helps somebody....would like to have this resolved in the next release.

P.S. This might also be the case for some fonts - .eot does not process on IE7/IE8, i.e. the @font-face css-rule is ignored (have not found a work around yet).

mzZzl,
JamBo 

Jul 28, 2011 at 12:11 PM

Thanks for pointing this out - we have added a 'blocking issue' for these missing mime types so this should be fixed in our next release.

Aug 2, 2011 at 3:29 PM

I did a fix. In the next version, there will be

a) all the  mime types you mentioned 

b) 195 extension/mimeTypes defined in .NET by default (see static constructor for internal class System.Web.MimeMapping)

c) All the mimeTypes that are defined in IIS7's web.config section will also be applicable

<configuration>
	<!-- ... -->
	<system.webServer>
	        <!-- ... -->
		<staticContent>
	                <!-- ... -->
			<remove fileExtension=".flv4" />
			<mimeMap fileExtension=".flv4" mimeType="video/mp4"/>
		</staticContent>
	</system.webServer>
</configuration>

Aug 2, 2011 at 4:44 PM

kudos!

Aug 3, 2011 at 7:17 AM

Brilliant!

Aug 3, 2011 at 12:02 PM

New feature described here:http://docs.composite.net/AddingMimeTypes

Thanks to @napernik for implementation and @wysocki for documentation!