4

I am sending a POST request with cURL to Flask Restful API as:

curl -X POST -H 'Content-Type: text/csv' -d @trace.csv http://localhost:5000/upload

I am not able to read this data from this request or I don't know how to read the data. Below is my implementation of the API:

class ForBetaAndUpload(Resource):
    def post(self, kind='quotes'):    
        parser = reqparse.RequestParser()
        parser.add_argument('file')
        args = parser.parse_args()['file']
        print(args) #Prints: Null

api.add_resource(ForBetaAndUpload, '/upload', endpoint='upload')

if __name__ == "__main__":
    app.run(debug=True)

How can I read the csv file data that I'm sending with cURL. I'll very much appreciate your help.

1 Answer 1

4

by default parser.add_argument will use GET params (location='args'). To get POST data, you need to specify location='form' in its arguments:

parser.add_argument('file', location='form')
Sign up to request clarification or add additional context in comments.

1 Comment

Got it. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.