'generates a INPUT file tag.
Optionally provides an A link to the file, including a checkbox so
the file can be deleted.
All is wrapped in a DIV.
@see: :meth:`FormWidget.widget`
@param download_url: Optional URL to link to the file (default = None)'

@classmethod
def widget(cls, field, value, download_url=None, **attributes):

    T = current.T
    default = {'_type': 'file'}
    attr = cls._attributes(field, default, **attributes)
    base_url = '/default/download'
    if (download_url and value):
        if callable(download_url):
            url = download_url(value)
        else:
            base_url = download_url
            url = ((download_url + '/') + value)
    else:
        url = None
    link = SPAN('[', A(T(cls.GENERIC_DESCRIPTION), _href=url), _class='s3-upload-link', _style='white-space:nowrap')
    requires = attr['requires']
    if ((requires == []) or isinstance(requires, IS_EMPTY_OR)):
        name = (field.name + cls.ID_DELETE_SUFFIX)
        delete_checkbox = TAG['']('|', INPUT(_type='checkbox', _name=name, _id=name), LABEL(T(cls.DELETE_FILE), _for=name, _style='display:inline'))
        link.append(delete_checkbox)
    link.append(']')
    if (not url):
        link.add_class('hide')
    preview_class = 's3-upload-preview'
    if (value and cls.is_image(value)):
        preview_url = url
    else:
        preview_url = None
        preview_class = ('%s    hide' % preview_class)
    image = DIV(IMG(_alt=T('Loading'), _src=preview_url, _width=cls.DEFAULT_WIDTH), _class=preview_class)
    inp = DIV(INPUT(**attr), link, image, _class='s3-upload-widget', data={'base': base_url})
    return inp
