content type of the uploaded file

K

ketulp_baroda

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?
 
D

Diez B. Roggisch

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.
 
C

Christian Tismer

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:[email protected]>
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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top