Reputation: 2556
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.
Upvotes: 4
Views: 3033
Reputation: 15738
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')
Upvotes: 4