def attach_file(request, contents, filename=None, content_type=None, size=None
    ):
    """Attach a file to a file request.

    This will mark the request as finished.

    :param request: the request
    :type request: bgfiles.models.FileRequest
    :param contents: the contents of the file/something that can be passed to a ``FileField``.
    :param filename: the filename; leave blank to maintain the current filename (if any)
    :type filename: str
    :param content_type: the content/mime type of the file; leave blank to maintain the current value (if any)
    :type content_type: str
    :param size: the size of the file in bytes; leave blank to maintain the current value (if any)
    :type size: int
    """
    request.attach_file(contents, filename, content_type, size=size)
    request.save()
