import mimetypes


def get_content_type(content, name):
    """
    Checks if the content_type is already set. Otherwise uses the mimetypes
    library to guess.
    """
    if hasattr(content.file, "content_type"):
        return content.file.content_type
    else:
        mime_type, encoding = mimetypes.guess_type(name)
        return mime_type