1

I have written the next Resource:

from config import AWS_S3_BUCKET
from flask_api import status
from flask_restful import Resource, reqparse
from werkzeug.datastructures import FileStorage
from werkzeug.utils import secure_filename
import helpers


class FileUpload(Resource):

    def post(self):
        parse = reqparse.RequestParser()
        parse.add_argument('user_file', type=FileStorage, location='user_file')
        parse.add_argument('user_id', type=int, location='user_id')
        args = parse.parse_args()
        file = args['user_file']
        if file:
            file.filename = secure_filename(file.filename)
            url = helpers.upload_file_to_s3(file, AWS_S3_BUCKET)
            return {'url': url}, status.HTTP_201_CREATED

        return 'Invalid file', status.HTTP_400_BAD_REQUEST

After I'm trying to upload my file in cURL by this command:

curl -F '[email protected]' -F 'user_id=5' http://127.0.0.1:5000/files/new

In the debugger the endpoint is called but all fields: user_file and user_id are NoneType.
What am I doing wrong?
P.S. The recovery.fstab file is located in the home directory.

1 Answer 1

1

See the flask-RESTful docs.

Location argument is where req parser get the values from.

def post(self):
    parse = reqparse.RequestParser()
    parse.add_argument('user_file', type=FileStorage, location='files')
    parse.add_argument('user_id', type=int, location='args')
    ...
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.