Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use CURL/CygWin to send files from local Windows machine to Server?

My goal is to upload a CouchDB document from my Windows machine to a remote server using cygwin/curl.

Here is a tutorial that shows how to do the same on a Mac: http://net.tutsplus.com/tutorials/getting-started-with-couchdb/

curl -X POST http://127.0.0.1:5984/mycouchshop/ -d @person.json -H "Content-Type: application/json

How can I do the same with Windows & CygWin?

like image 528
edt Avatar asked May 15 '11 00:05

edt


People also ask

How do I use curl to transfer files?

How to send a file using Curl? To upload a file, use the -d command-line option and begin data with the @ symbol. If you start the data with @, the rest should be the file's name from which Curl will read the data and send it to the server. Curl will use the file extension to send the correct MIME data type.


2 Answers

After opening cygwin.

step 1 - CD into the directory that contains the file you would like to post via CURL:

cd ../
cd /cygdrive/c/Users/[put user name here]/Documents/[more directories here]/

Note: The strange part is having to go through the "cygdrive" directory.

step 2 - Use CURL to send the file:

curl -X POST http://mywebsite.com/path/to/directory -d @some_file.extension -H "Content-Type: application/json"

Replace "mywebsite.com...", "some_file.extension" and "application/json" with actual values.

like image 128
edt Avatar answered Oct 13 '22 11:10

edt


Looks like you got it. Also on Windows, the single-quote (') is not allowed. Use double-quote for your JSON data and then use \" for double-quotes inside the JSON.

curl -XPUT http://localhost:5984/db/doc -d "{\"like\": \"this\"}"
like image 42
JasonSmith Avatar answered Oct 13 '22 10:10

JasonSmith