반응형

다운로드 받을 파일 타입(Mimetype) 구분 방법

import mimetypes

mimetypes.guess_type('test.png')  # return ('image/png', None)

 

 

    import mimetypes
    import urllib
    
    
    file_name = urllib.parse.quote(file_info.file_name.encode('utf-8'))

    if os.path.exists(file_path):
        with open(file_path, 'rb') as fh:
            response = HttpResponse(fh.read(), content_type=mimetypes.guess_type(file_path)[0])
            response['Content-Disposition'] = 'attachment;filename*=UTF-8\'\'%s' % file_name
            return response

 

반응형

+ Recent posts