Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Detect mime-type without download

Detect mime-type without download

Scheduled Pinned Locked Moved C#
phpcomquestion
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SilverV
    wrote on last edited by
    #1

    If I have the URL of a file e.g. http://mysite.com/file.php?f=1 where I cannot see the extension of the file is it possible to determine the mime-type of the file without downloading it first?

    G 1 Reply Last reply
    0
    • S SilverV

      If I have the URL of a file e.g. http://mysite.com/file.php?f=1 where I cannot see the extension of the file is it possible to determine the mime-type of the file without downloading it first?

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      You can download first several bytes and use Magic Numbers to detect type

      Giorgi Dalakishvili #region signature my articles #endregion

      S 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        You can download first several bytes and use Magic Numbers to detect type

        Giorgi Dalakishvili #region signature my articles #endregion

        S Offline
        S Offline
        SilverV
        wrote on last edited by
        #3

        But then I would need a lookup table, don't I? Is there no way this could be done with the .net framework? There are applications which have exactly this kind of functionality for example if you click on a download link with most browsers they display the mime-type without downloading. How is it done there?

        L 1 Reply Last reply
        0
        • S SilverV

          But then I would need a lookup table, don't I? Is there no way this could be done with the .net framework? There are applications which have exactly this kind of functionality for example if you click on a download link with most browsers they display the mime-type without downloading. How is it done there?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, normally a HTTP request performs a GET to receive the entire page. however you can also do a HEAD which requests just the head information, which often includes the mime-type, whereas the body is not transfered at all. I once did HTTP with the Socket class; I trust you can do it with HttpRequest too. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups