How to use curl to upload and post a file with the following form

curlupload

The form html from the page I'm trying to upload to is as follows:

<form action="upload_handler" method="POST" enctype="multipart/form-data">
    <input type="file" name="myfile">
    <input type="submit" name="submit" value="Upload">
</form>

I've tried the following, but neither works:

curl -b cookies.txt -F "myfile=@/xxx/java_pid30806.hprof;submit=Upload" http://xxx.yyy.com > curlout.txt

curl -b cookies.txt --data-binary @/xxx/java_pid30806.hprof http://xxx.yyy.com > curlout.txt

,where cookies.txt contains the session cookie obtained from succesfully logging in via a previous curl command.

Best Answer

First of all your command have a mistake: -b is not used with cookiejar i.e cookie file. You should use -c. -b is to specify individual cookie.

Try this:

curl -c cookies.txt --form myfile=@/path/to/file --form submit=Upload http://xxx.yyy.com