Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5997751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:18:30+00:00 2026-05-23T00:18:30+00:00

Using only JavaScript and framework like dojo/jQuery… Is there a way to find the

  • 0

Using only JavaScript and framework like dojo/jQuery…

Is there a way to find the Content-Type for a particular file name extension?

Say if I type in the string “something.pdf”, I want to show an alert that says “application/pdf”

or “something.html” show “text/html”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:18:31+00:00Added an answer on May 23, 2026 at 12:18 am

    I think you will need to maintain the mappings yourself (you could XHR a physical file and get it, but I doubt you want to do that)…

    (function() {
    
        var extToMimes = {
           'img': 'image/jpeg',
           'png': 'image/png',
           ...
        }
    
        window.getMimeByExt = function(ext) {
            if (extToMimes.hasOwnProperty(ext)) {
               return extToMimes[ext];
            }
            return false;
        }
    
    })();
    

    jsFiddle.

    This will return false if it doesn’t exist in your mapping. If you like, you could just return the extToMimes[ext], which will give undefined if it doesn’t exist. It also won’t accidentally get things up the prototype chain.

    There is also the option of accessing it if it is a file input.

    var mime = $('input[type="file"]').prop('files')[0].file;
    

    Keep in mind the extension to mime type makes no guarantees about the actual file itself; you’d need to parse it server side to determine what kind of file it really is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Without using a JavaScript framework like jQTouch and jQuery Mobile, is there a way
Using only ANSI C, is there any way to measure time with milliseconds precision
Using only grep and sed, is there a way I can tranform the output
I am trying to write my own Javascript Framework something like jQuery. I use
I have a very large javascript file I would like to load only if
I am trying to create a form using only JavaScript. I mean create a
how can I open a modal window using javascript only. I can't use own
How to strip off HTML tags from a string using plain JavaScript only, not
I have one page website only using HTML, CSS and JavaScript. I want to
Using only ANSI C, what is the best way to, with fair certainty, determine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.