POST csv/Text file using cURL

Krishnang K Dalal picture Krishnang K Dalal · Jun 23, 2018 · Viewed 16.2k times · Source

How can I send POST request with a csv or a text file to the server running on a localhost using cURL.

I have tried curl -X POST -d @file.csv http://localhost:5000/upload but I get

{ "message": "The browser (or proxy) sent a request that this server could not understand." }

My server is flask_restful API. Thanks a lot in advance.

Answer

Harshit Garg picture Harshit Garg · Jun 23, 2018

There are many alternate ways to accomplish this. One way is I have used the following:

curl -F ‘data=@<file_location>’ <URL>

Eg. curl -F [email protected] localhost:5000/h

Your command can also be changed slightly like this

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

The above is one of the many ways.It can be sent either as a part of form or data, or multipart, etc. You can refer Medium Post