Transfer a file to httpserver via POST command from curl
Chris Angelico
rosuav at gmail.com
Thu Dec 12 11:54:53 EST 2019
On Fri, Dec 13, 2019 at 3:44 AM Karthik Sharma <karthik.sharma at gmail.com> wrote:
> I am doing a POST using curl as follows.
>
> curl -X POST --data-binary @/home/user/testfile.txt http://
> 127.0.0.1:5000/file-upload
>
> Is it really possible to transfer a large binary file from my machine to
> the above httpserver via POST command and download it again? If yes, is the
> above Flask app enough for that and what am I doing wrong?
I think your Flask code is okay (haven't checked in detail, but at
first glance it looks fine), but for file uploads to be recognized in
request.files, you'll need to change the way you run curl.
Try this:
curl -F 'file=@/home/user/testfile.txt' http://127.0.0.1:5000/file-upload
The word "file" in there ends up as the key in request.files (so if
you used "spam=", you'd get request.files["spam"]), and you can add
other form data as well if you choose.
ChrisA
More information about the Python-list
mailing list