noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.73k stars 506 forks source link

Upload File Example Broken #576

Open patientplatypus opened 5 years ago

patientplatypus commented 5 years ago

This code (https://flask-restplus.readthedocs.io/en/stable/parsing.html#file-upload):

from werkzeug.datastructures import FileStorage

upload_parser = api.parser()
upload_parser.add_argument('file', location='files',
                           type=FileStorage, required=True)

@api.route('/upload/')
@api.expect(upload_parser)
class Upload(Resource):
    def post(self):
        uploaded_file = args['file']  # This is FileStorage instance
        url = do_something_with_file(uploaded_file)
        return {'url': url}, 201

Doesn't compile. Maybe you need something like this args = upload_parser.parse_args('file'), but args is clearly not defined.

I've wasted too much time on this for me to consider using your library and it's obnoxious that you have code examples that don't work. Fix this.

Colin-b commented 5 years ago

I'm not sure your tone is adequate here... There is indeed a mistake, thanks for pointing it out, you could submit a PR to fix it now that you found the issue.

Python is easy to access as a language but imho you should try to dig a bit more into the fundamentals before copy/pasting code.

Note that args could also be related to flask.request.args (even if using Flask restplus is the right way to do it in this case).