Re: File upload: how to validate file type

2009-03-29 Thread Torsten Bronger
Hallöchen! Torsten Bronger writes: > I'd like to ensure that people only upload PDF files, so the file > must start with "%PDF". If the file starts with something else, > the form must not validate. > > How do I do that? I though about a clean_... method which reads > the start of the file and

Re: File upload: how to validate file type

2009-03-29 Thread Torsten Bronger
Hallöchen! P M writes: > yes you can, because signature of pdf is in the starting of 1st > chunk of stream... rest of the things are of hardly interest for > libmagic identification... Again, this is not the point. The point is whether I can safely read the first bytes and put them back into t

Re: File upload: how to validate file type

2009-03-28 Thread P M
yes you can, because signature of pdf is in the starting of 1st chunk of stream... rest of the things are of hardly interest for libmagic identification... what ever method you are using to handle the chunks/streams is still the same, regardless of type of data user is uploading, one more tip

Re: File upload: how to validate file type

2009-03-28 Thread Torsten Bronger
Hallöchen! P M writes: > there are various ways to check, but best will be to use > Python-libmagic interface... it did worked well for me .. Thank for the hint, however, the interesting part is whether I can safely tamper with the file object in the clean method, so that the actual download wi

Re: File upload: how to validate file type

2009-03-28 Thread P M
servus, there are various ways to check, but best will be to use Python-libmagic interface... it did worked well for me .. mit freundliche Grüß On Sat, Mar 28, 2009 at 10:16 PM, Torsten Bronger < bron...@physik.rwth-aachen.de> wrote: > > Hallöchen! > > I'd like to ensure that people only upload

File upload: how to validate file type

2009-03-28 Thread Torsten Bronger
Hallöchen! I'd like to ensure that people only upload PDF files, so the file must start with "%PDF". If the file starts with something else, the form must not validate. How do I do that? I though about a clean_... method which reads the start of the file and then re-opens it. Is this a good i