def guess_content_type(file_path, mime_types, charset):
    """Guess the content type of a file based on filename.
    Charset will be assigned to a mime subtype of "text".

    Raise ValueError if the mime type of a file cannot be determined.
    """
    content_type, encoding = mime_types.guess_type(file_path)
    if content_type is None:
        raise ValueError('Could not find mime type for "%s"' % file_path)
    if content_type.startswith('text/'):
        content_type += '; charset=' + charset
    return content_type
