content type of the uploaded file

Discussion in 'Python' started by ketulp_baroda@yahoo.com, Feb 23, 2004.

  1. Guest

    Hi
    I want to determine the content type of uploaded file.
    File was uploaded by using <input type=file>.
    How can I determine the content type?
     
    , Feb 23, 2004
    #1
    1. Advertising

  2. wrote:
    > I want to determine the content type of uploaded file.
    > File was uploaded by using <input type=file>.
    > How can I determine the content type?


    I don't know if the http-spec does require a mime-type - neverless you can't
    and shouldn't trust that a uploaded file is what the user wants you to
    believe it is.... so it would be the best to invoke 'file' on your received
    file. It has the -i option to give you the mime-type.

    --
    Regards,

    Diez B. Roggisch
     
    Diez B. Roggisch, Feb 23, 2004
    #2
    1. Advertising

  3. wrote:

    > Hi
    > I want to determine the content type of uploaded file.
    > File was uploaded by using <input type=file>.
    > How can I determine the content type?


    For uploading files, your form tag should specify the attribute
    ENCTYPE="multipart/form-data"
    since that makes the browser send mime-encoded files
    with all necessary headers, like "Content-Type".
    It depends on the package you are using, how to get at this
    header information.
    If you are using the CGI module, you will interrogate the
    FieldStorage item. For further reference,
    http://www.python.org/doc/current/lib/node403.html
    might help.

    ciao - chris

    --
    Christian Tismer :^) <mailto:>
    Mission Impossible 5oftware : Have a break! Take a ride on Python's
    Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
    14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
    work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776
    PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
    whom do you want to sponsor today? http://www.stackless.com/
     
    Christian Tismer, Feb 23, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt G
    Replies:
    1
    Views:
    1,162
    Deepak Kumar Vasudevan
    Aug 22, 2003
  2. Spotted Owl Eater

    Determine the File Type of an Uploaded File

    Spotted Owl Eater, Nov 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,855
    Patrice
    Nov 16, 2005
  3. Replies:
    2
    Views:
    2,716
  4. Mark
    Replies:
    4
    Views:
    784
  5. Roberto
    Replies:
    3
    Views:
    312
Loading...

Share This Page