On 1/30/06, tonemcd <[EMAIL PROTECTED]> wrote: > I didn't think you could do that - find out the size of an file to > upload *before* it's uploaded, and act upon it. I've wanted to do that > in CGI, Perl, PHP and Zope, and never figured out how to do it (it > would have saved a few embarrasing incidents in the past; the 170 Mbyte > powerpoint, the CD!! that was uploaded, etc. etc.) > > I'd like to see the validator you come up with Arthur!
def isSmallFile(self, field_data, all_data): if len(field_data["content"] > 10000: # 10,000 bytes raise validators.ValidationError, "Please enter a smaller file." The trick here is to operate on field_data['content'] instead of field_data. File-upload fields are a special-case; they come across as a dictionary of {'filename', 'content-type', 'content'}. Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org