먼저 그런 다음 새로운 추가 파서에게
# parsers.py
import werkzeug
from flask_restplus import reqparse
file_upload = reqparse.RequestParser()
file_upload.add_argument('xls_file',
type=werkzeug.datastructures.FileStorage,
location='files',
required=True,
help='XLS file')
를 구성해야 리소스를 귀하의 api 네임 스페이스에 추가하십시오.
# api.py
import …
import parsers
@api.route('/upload/')
class my_file_upload(Resource):
@api.expect(parsers.file_upload)
def post(self):
args = parsers.file_upload.parse_args()
if args['xls_file'].mimetype == 'application/xls':
destination = os.path.join(current_app.config.get('DATA_FOLDER'), 'medias/')
if not os.path.exists(destination):
os.makedirs(destination)
xls_file = '%s%s' % (destination, 'custom_file_name.xls')
args['xls_file'].save(xls_file)
else:
abort(404)
return {'status': 'Done'}
이 도움이되기를 바랍니다.
출처
2016-11-11 12:31:10
k3z
단일 게시물 메서드에서 여러 유형/이벤트가 있으면 내 의견을이 모듈 스타일로 유지할 수 없습니다. 보내기 메소드 (파일 업로드)는'post'이지만, 어딘가에서 파일을 쓰기 위해 체크 할 필요가 있기 때문에 결코이 방법을 사용하지 않았습니다! 큰 파일에서 복잡하기 때문에 대상과 동기화 된 소스가 필요합니다 (diff를 만드는 것만 제거하거나 이동하지 마십시오). 일부 데이터 또는 escape_multiple_io 작업을 잃지 않으려면 소스 코드/html 출력에 추가 버전을 사용해야합니다. 작은 크기의 파일이있는 경우 Base64로 인코딩 된 bz2 콘텐츠를 사용하십시오. 큰 파일 (큰 파일 (서버에서))은 프로세스 생성/수정시 많은 위험이 있습니다. – dsgdfg