[html-formfu] new file upload constraints

Carl Franks fireartist at gmail.com
Fri Jan 18 13:26:26 GMT 2008


In svn , there's now a File::Size constraint, with min() and max() methods.
You can set either or both methods.
These check against the browser-submitted Content-Length (byte count).

    constraints:
      name: file
      type: File::Size
      min: 1
      max: 10_000_000

There's a File::MIME constraint with types() and regex() methods.
types() accepts either a single MIME-type, or an array-ref of MIME-types.
If none of these exactly match the browser-submitted Content-Type (or
types() wasn't set), then regex() is matched against it.
The regex uses the '\x' flag, so whitespace is ignored.

    constraints:
      name: file
      type: File::MIME
      regex: '^ image / (?: jpeg | png ) \z'


There's also a 'File' constraint, to ensure a file was uploaded, but
this is unnecessary if any of the File::* constraints are used, as
they all do the same test anyway.
Read the "limitations" section in it's docs, if you plan on using it.

Carl



More information about the HTML-FormFu mailing list