validators.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:41Inc 作者: MikeShi42 项目源码 文件源码
def validate_video_file(upload):
    """
    Validates uploaded file name by using mimetypes, part of Python standard
    library, to guess the mime type from the file extension.

    The file extension is not a reliable way to determine mime type. A better
    alternative is using the python-magic library, but that requires the
    libmagic library which is extra overhead, so not worth.
    """
    mime_type = mimetypes.MimeTypes().guess_type(upload.name)[0]
    if mime_type not in VIDEO_MIME_TYPES:
        raise ValidationError('File type not supported. MP4, Quicktime, or WebM recommended.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号