Given a URL like http://www.....jpg
, how can I get the MIME type in Angular? e.g. image, audio, or video?
I understand that the MIME type can be found with file uploads as was explained here.
Given a URL like http://www.....jpg
, how can I get the MIME type in Angular? e.g. image, audio, or video?
I understand that the MIME type can be found with file uploads as was explained here.
In order to answer this question I will have to make a few assumptions:
http://www.....jpg
could be located on any server, not only yoursImagine this scenario:
Your angular app is hosted on www.myserver.com
. Someone visit your site, loads and runs your angular code in their browser.
Now you want their browser to investigate the mime type of www.someimage.com/1.jpg
. Loading that file would be a Cross-Origin request which is not allowed by default. If you have access to both servers you can allow this type of request by implementing Cross-Origin Resource Sharing for certain URIs, but that's not going to help you.
HTTP implements content negotiation for URIs. This wikipedia article explains it well. This is important here because:
A resource may be available in several different representations; for example, it might be available in different languages or different media types.
Although you will not be able to check for MIME types for an arbitrary URI using client-side (angular) code, you can still solve this by implementing a small http service on your server. The flow would be something like this: