jpsnow72
jpsnow72

Reputation: 995

Get the type of file of a Media Server URL (no extension) with JavaScript

If I have a file being served by a Media Server and therefore the URL has no file extension, how can I use JavaScript to find out what the extension actually is?

For example, lets say this is my url:

/MediaServer?MediaID=SomeRandomMediaIDWithoutExtension

I would like to use JavaScript to determine what type of media resides at that URL.

Upvotes: 0

Views: 163

Answers (1)

Jeremy M.
Jeremy M.

Reputation: 1164

You could get the response header. For exemple :

$.ajax({
   type: 'GET',
   url:'/MediaServer?MediaID=SomeRandomMediaIDWithoutExtension',
   success: function(data, textStatus, request){
        alert(request.getResponseHeader('Content-Type'));
   }
  });

Content-Type header

Or use Content-Disposition header. Wish returns possibly returns you filename. (Thanks yo @bhspencer)

As you said you'r looking for SRT / VTT

Those two files are formated differently so you could compare first lines of your file to determine his format.

Upvotes: 2

Related Questions