You have the file string in memory, presumably as a string, so just look at the indicated bytes like you would any other string. I forgot about the file command, but that requires the file to be written to the harddrive as far as I can tell, and you may not want the extra overhead. Although, if you anticipate most files passing their validation, and the ones that do get written to disk anyway, it might be a better solution.

On 10/31/2013 06:18 PM, Claudio Dusan Vega Ozuljevich wrote:
how to? do I have to use a module or web.py? Also, the file is in
memory, as uploaded (in order to validate it) by a template (html
using <input type=file>).

Thanks for the fast response.

On Thu, Oct 31, 2013 at 7:08 PM, Steven Brown <[email protected]> wrote:
You could look at file signatures:

https://en.wikipedia.org/wiki/List_of_file_signatures

Of course that doesn't guaruntee that the file is valid/conforms to the
format.


On 10/31/2013 02:32 PM, Claudio Dusan Vega Ozuljevich wrote:
Hi guys!

Sorry for the noob question, but I just learned programming and I'm
still struggling to get the hang of it.

I need to know if there is a way to check the file type (pdf, doc,
jpeg etc) of an uploaded file, so I can store it just if it complies
with my requirements. Fo example, I want to check if a file is an
image (jpeg), an in case it is store it and in case it isn't just show
an error message.

I'm not referring the issue as "the extension" of the file, because
the extension can be change and file would still be a .exe but just
with the ".jpeg" extension.

Thanks beforehand.

--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to