From c262676ba67dffb1bfe6345a189bf415add3ff1f Mon Sep 17 00:00:00 2001 From: Yohe1 Date: Sun, 24 Nov 2019 07:20:25 +0900 Subject: [PATCH 1/2] [fix]Get file object from Flask object Despite the fact that it can be commented that FileObject can be obtained in this line, it was not a valid code, so it was modified. --- doc/parsing.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/parsing.rst b/doc/parsing.rst index 926a9f87..40154c19 100644 --- a/doc/parsing.rst +++ b/doc/parsing.rst @@ -234,6 +234,7 @@ and to set the type to :class:`~werkzeug.datastructures.FileStorage`. .. code-block:: python + from flask import request from werkzeug.datastructures import FileStorage upload_parser = api.parser() @@ -245,7 +246,7 @@ and to set the type to :class:`~werkzeug.datastructures.FileStorage`. @api.expect(upload_parser) class Upload(Resource): def post(self): - uploaded_file = args['file'] # This is FileStorage instance + uploaded_file = request.files['file'] # This is FileStorage instance url = do_something_with_file(uploaded_file) return {'url': url}, 201 From 41cfefaf715783dab4e22d2efd6669e75fdcc1be Mon Sep 17 00:00:00 2001 From: NAM-MAN Date: Tue, 26 Nov 2019 03:07:01 +0900 Subject: [PATCH 2/2] [modify] Change to Parse instead of using Flask Request. --- doc/parsing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/parsing.rst b/doc/parsing.rst index 40154c19..b1ba0536 100644 --- a/doc/parsing.rst +++ b/doc/parsing.rst @@ -234,7 +234,6 @@ and to set the type to :class:`~werkzeug.datastructures.FileStorage`. .. code-block:: python - from flask import request from werkzeug.datastructures import FileStorage upload_parser = api.parser() @@ -246,7 +245,8 @@ and to set the type to :class:`~werkzeug.datastructures.FileStorage`. @api.expect(upload_parser) class Upload(Resource): def post(self): - uploaded_file = request.files['file'] # This is FileStorage instance + args = upload_parser.parse_args() + uploaded_file = args['file'] # This is FileStorage instance url = do_something_with_file(uploaded_file) return {'url': url}, 201