Skip to content

Upload list of files using restX + Swagger #177

Open
@maory69

Description

@maory69

Hey,

I'm trying to upload a list of files to my post method using the swaggerUI
I am defining my input using RequestParser and add_argument method.
Uploading one file works just fine, but once I'm adding 'action=append' to make it a list of files it doesn't work.

my code looks like this:

from flask_restx import Namespace, Resource, reqparse
from werkzeug.datastructures import FileStorage
upload_parser = reqparse.RequestParser()
upload_parser.add_argument('images', location='files',
                           type=FileStorage, required=True, action="append")


@api.route("/")
class MyResource(Resource):
    @api.expect(upload_parser)
    def post(self):
        args = upload_parser.parse_args()
        images = args['images']

This is the cUrl from swagger:
curl -X POST "http://127.0.0.1:8000/" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "images=%5Bobject%20File%5D&images=%5Bobject%20File%5D"

And the problem is that swagger sends it as application/x-www-form-urlencoded and not multipart/form-data
Saying again, if I don't add the action='append' to the add_argument method, and I only send one file using Swagger it sends it as multipart/form-data

Is there any way to control it?

Screen Shot 2020-07-20 at 19 25 22

Screen Shot 2020-07-20 at 19 25 33

Screen Shot 2020-07-20 at 19 25 40

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions