5.2.2.17 type="..." attribute (file)
Description: type=
Keywords: albatross

###
5.2.2.17 `type="..."` attribute (file)

The tag determines the generated `name` (5.2.2.5) from the `name` related attributes.

If you are using an execution context that inherits from the `NameRecorderMixin` (7.5) then using this input field type will automatically cause the enclosing `<al-form>` (5.2.1) tag to include an `enctype="multipart/form-data"` (5.2.1.2) attribute.

For example:

    >>> import albatross
    >>> class Ctx(albatross.SimpleContext):
    ...     def input_add(self, *args):
    ...         print args
    ...
    >>> ctx = Ctx('.')
    >>> albatross.Template(ctx, '<magic>', '''
    ... <al-input type="file" name="resume" whitespace>
    ... ''').to_html(ctx)
    ('file', 'resume', None, 0)
    >>> ctx.flush_content()
    <input type="file" name="resume" />

After writing all tag attributes the execution context `input_add()` method is called with the arguments; input field type (`'file'`), the generated `name`, `None`, and a flag indicating whether or not the `list` (5.2.2.4) attribute was present.

The request merging allows the user to submit more than one file in a `file` input field. To simplify application code the `Request` always returns a list of `FileField` objects for `file` inputs.

Application code to process `file` inputs typically looks like the following:

    def page_process(ctx):
        if ctx.req_equals('resume'):
            for r in ctx.locals.resume:
                if r.filename:
                    save_uploaded_resume(r.filename, r.file.read())