반응형
다운로드 받을 파일 타입(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
반응형
'프로그래밍 언어 > Python3' 카테고리의 다른 글
Python.h: No such file or directory 에러 (0) | 2020.03.28 |
---|---|
AWS 아마존 리눅스에 파이썬(Python 3.8) 설치 방법 (0) | 2020.03.28 |
Django 이미 있는 DB 테이블을 models 생성하고 싶을때 (0) | 2020.03.15 |
pip install mysqlclient 에러 / 'mysql.h': No such file or directory (0) | 2020.03.03 |
no acceptable C compiler found in $PATH (0) | 2019.09.01 |