Reputation: 4693
I have the following method to post data to server :
curl --ipv4 http://localhost:3000/api/tests/1 -d @test.csv
I am trying to post a file with curl to a meter app
In meteor I am not able to read the data because I cant attach a key to the curl option data arrives as the key itself
example
contents of test.csv = > 1,1,1
at server
console.log('route to host' , this.request.body); yields {{1,1,1} : ''}
And yes I even tried -F [email protected] with no success as well
How can I add a key and make the contents of the file as value when posting through curl?
Upvotes: 2
Views: 192
Reputation: 4693
This works!!
curl --ipv4 --data-urlencode "[email protected]" http://localhost:3000/api/tests/1
Hope this helps someone :)
Upvotes: 0
Reputation: 1825
basically -d for curl means read the file and use its content as data
If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar. When --data is told to read from a file like that, carriage returns and newlines will be stripped out. If you don't want the @ character to have a special interpretation use --data-raw instead.
in order to send the file itself youll need something like -F
(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388. This enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.
Example, to send your password file to the server, where 'password' is the name of the form-field to which /etc/passwd will be the input:
curl -F password=@/etc/passwd www.mypasswords.com
in your case probably use -F curl --ipv4 http://localhost:3000/api/tests/1 -F data=
if you want to file to be uploaded as a file use -F [email protected]
Upvotes: 1