Forums

How to set MIMETYPES on server

Hi i have a problem similar to this one: http://stackoverflow.com/questions/8831625/html5-audio-not-working-on-firefox I need to be able to set the mime-type of ogg files so that it plays without problems on the browser. How do i set these mimetypes on pythonanywhere ? Please help me resolve this issue.

Thanks.

Hi there -- a few questions:

  • How are you serving the files? That is, ss it from a static file, or a web application you've written?
  • If it's a static file, what's the file extension?

I'm serving out files with my django application. They are all static files and every other file works perfectly except for .ogg files. I know that the fix is to add the mimetype to the webserver. It currently serves it out as "application/octet-stream" where it should server it out as "application/ogg" Is there a way for me to add it here with pythonanywhere ?

references : https://developer.mozilla.org/en-US/docs/Configuring_servers_for_Ogg_media http://www.developershome.com/wap/wapServerSetup/tutorial.asp?page=settingUpMIME

Please help me with this issue i am really thinking about buying premium for my website if all works well here.

Thanks for your reply.

That's strange. If you're using Django, it will ultimately use the Python mimetypes module to guess the type of the file. I've double-checked, and it looks like it should work for ogg files:

>>> import mimetypes
>>> mimetypes.guess_type("foo.ogg")
('audio/ogg', None)

Could you give me a URL on your site that shows the problem?

No i'm sure there is some kind of problem as i added the mimetype on my IIS server for .ogg as application/ogg and it worked perfect. This issue is only on Firefox so please visit http://abhisheks91.pythonanywhere.com and login with U:test/P:test and click on start survey. If your in firefox you will see the following error in firebug

"HTTP "Content-Type" of "application/octet-stream" is not supported. Load of media resource http://abhisheks91.pythonanywhere.com/static/media/<filename>.ogg failed."

Also this is what i got in my bash:

import mimetypes
mimetypes.guess_type("foo.ogg")
(None, None)

PS: I'm using django 1.4 by setting up a virtual env.

Thanks for the update! I'll investigate further, and report back as soon as I know more.

Sure, i really wish you can help me fix this issue. Thanks again.

Sorry for the slow reply. I think I've got it -- looks like a bug on our side, your sandbox was missing a file that tells the mimetypes module what the mapping from file extensions to mime types is. I've patched it for your account specifically, so if you try again now, it should work. If it does, could you let me know? Then we'll be able to make it a general fix for everyone.

Thanks for reporting this!

It still gives me the same error in firebug, i.e. OGG files are still coming down as "application/octet-stream".

That's strange. Have you restarted your web application? Also, could you try running mimetypes.guess_type("foo.ogg") in a console again?

I'm sorry.. yes restarted the server and it now works. Thanks a lot for the fix :) Although i still get "(None, None)" on trying to guess mimetype of a .OGG file.

No problem, I should have told you you'd need to restart the app!

It's actually rather odd that you're still seeing the problem when you use guess_type -- I'd expect both to work, or neither... Perhaps you're running the guess inside an old Python console? I think the mimetypes module tries to read the missing config file the first time you use it, and then caches the result until you exit the process.

Anyway, if the change I made solved the problem then we should get it done for everyone. It's pretty simple so I think I can promise it for the next release.

Sounds good :) Thanks for the quick fix.

I am getting a very similar problem. When encoding and audio file in javascript I get the following error: "Uncaught could not load memory initializer Mp3LameEncoder.min.js.mem"

The HTML file with the corresponding javascript libraries are in the static folder and the HTML file is called as "TemplateView" in the Django application.

PS: The code without Django/Python has been tested on another server and worked without issues.

From what I gather the webserver has to be configured to support these ".mem" files <system.webServer> <staticContent> <mimeMap fileExtension=".mem" mimeType="text/html" /> </staticContent> </system.webServer>

Any idea how I can resolve this issue?

.mem files are not currently supported -- we have a ticket for that and I added them on your behalf.

Thank you for the quick reply.

You mention that you have a ticket for this issue. Does this mean that ".mem" files will be supported? If yes can you tell me when you think ".mem" files will be supported?

Yes, I've already marked you in the corresponding ticket.

Thank you for adding me to the ticket.

The missing MimeType is currently preventing us from rolling out promised functionality for our customers. Can you tell me when you think the MimeType ".mem" will be available?

It's impossible to tell at the moment.

Any indication if it is days, weeks or months?

Reason for asking is that this will determine our course of action as we have customers waiting for functionality that we have already running in our dev system.

Is there any reason why this config change in the PythonAnywhere webserver would not be possible?

Config changes like this require a new system image, which is a large amount of work; we can't change existing system images because that would run the risk of breaking existing working sites. We do have a new system image on its way, which will support Python 3.10 (among many other things) and this is a small change that we can easily put into that image. But I would say that it's at least a month away.

Is there some way that you can serve the specific files in question using Python code? Then you would be able to set any headers you like.

Thank you for explanation.

We have implemented an alternative with the use of the MediaDevice API which is only recently also become available on iOS Safari (mediakit). The downside is that it only supports iPhone, iPad that have a very recent version of iOS 14.5 and higher.

However still looking forward to the mimetype mem to be supported as there might be other js libraries that are using it :).

@dmenis Glad to hear that you made it work somehow!