Can't upload file to a server using curl - file-upload

I'm trying to upload a file to a server using curl. It should be uploaded a binary file regardless the format it is in. But I'm having an error:
curl -d #/home/alex/123.log localhost:9000/myupload/
The error (the warning, actually) is
Warning: Couldn't read data from file "123.log", this makes an empty POST.
P.S. Shouldn't I use --data-binary instead of -d? I didn't find any documentation for --data-binary.

Copied from Curl's document:
-d, --data is the same as --data-ascii. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form field you may use --data-urlencode.
More about the --data-binary parameter.
Note: Make sure you have permission to access the file that you wanted to upload to the sever.

Related

Downloading PDF report from kibana/elasticsearch using API call

I am trying to generate PDF reports and download them using a script. I followed below instructions.
https://github.com/elastic/kibana/blob/master/docs/user/reporting/automating-report-generation.asciidoc
I am able to queue the report and i also got a download url ()/api/.../download/xyzdrfd but when i am trying wget on the url, It's not working. I have no idea how to download that report using APIs so just tried with wget.
Can anyone tell me how to download the reports from API call?
The download might not be happening due to some redirects happening on the page. Use -L option with curl command to get it working. I did it specifically using the Kibana endpoint to download a PDF file. Replace the username and passsword with the basic auth credentials of yours. Use -o option to specify the downloaded file name. Below is the complete example of the command:
curl -L -u username:password -o download.pdf https://endpoint.com:9244/s/bi-/api/reporting/jobs/download/ktl8n95q001edfc210feaz0r

IBM Watson Text to Speech Output File has No Sound

I tried the IBM Watson Text to Speech curl example, it produced a .wav file. I also generated an .mp3, and .ogg files. none of them would play a sound output. I am using Windows 10.
curl -X POST -u "apikey:{my apikey}" --header "Content-Type: application/json" --data "text:hello world" --output hello_world.ogg "{my url}/v1/synthesize/"
If your audio files are not playing, then the chances are that they are not audio files. You are directing any output into your "audio" files, this includes any error messages. If you cat or browse an "audio" file, you will see that it contains text indicating why an audio file was not generated.
I guess this is a duplicate of Having issues with IBM Watson TTS using Curl
Answer update
Re: your comment - That error is typical of a json conversion error. Looking at the API documentation - https://cloud.ibm.com/apidocs/text-to-speech#synthesize - the API is expecting the input data in a json format.
ie.
--data "{\"text\":\"Hello world\"}"

cURL API Commands

I have a question about API's and cURL. I'm not sure if this is all Python, but I am trying to access JSON data using an API, but the server isn't as easy as grabbing the data with an XMLRequest... The support team gave me this line of code:
curl -k -s --data "api_id=xxxx&api_key=xxxx&time_range=today&site_id=xxxxx"
https://my.incapsula.com/api/stats/v1
And I have no idea what this even means because all the API requests I've been making was just as easy as using a link and parsing through it with some JavaScript. Can anyone break the -k -s --data for me or point me in a right tutorial?
(NOT PYTHON; Sorry guys...)
The right tutorial is the man page.
-k/--insecure
(SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default. This makes all connections considered "insecure" fail unless -k/--insecure is used.
See this online resource for further details: http://curl.haxx.se/docs/sslcerts.html
-s/--silent
Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.
As for --data, well, it specify the data you are sending to the server.
This question is (for now) not related to Python at all, but eventually to shell scripting.

How to download all my caldav and carddav data with one wget / curl?

Until now, I used Google Calender and do my personal backup with a daily wget of the public ".ics"Link.
Now I want to switch to a new Service who has only caldavaccess.
Is there a possibility to download all my caldav and carddav data with one wget / curl?
This downloaded data should give me the possibility to backup lost data.
Thanks in advance.
edit
I created a very simple php file which works in the way hmh explained. Don't know if this way works for different providers, but for mailbox.org, it works well.
You can find it here https://gist.github.com/ahemwe/a2eaae4d56ac85969cf2.
Please be more specific, what is the new service/server you are using?
This is not specifically CalDAV, but most DAV servers still provide a way to grab all events/todos using a single GET. Usually by targeting the relevant collection with a GET, e.g. like either one of those:
curl -X GET -u login -H "Accept: text/calendar" https://myserver/joe/home/
curl -X GET -u login -H "Accept: text/calendar" https://myserver/joe/home.ics
In CalDAV/CardDAV you can grab the whole contents of a collection using a PROPFIND:
curl -X PROPFIND -u login -H "Content-Type: text/xml" -H "Depth: 1" \
--data "<propfind xmlns='DAV:'><prop><calendar-data xmlns='urn:ietf:params:xml:ns:caldav'/></prop></propfind>" \
https://myserver/joe/home/
Replace calendar-data with
<address-data xmlns="urn:ietf:params:xml:ns:carddav"/>
for CardDAV.
This will give you an XML entity which has the iCal/vCard contents embedded. To restore it, you would need to parse the XML and extract the data (not hard).
Note: Although plain standard, some servers reject that or just omit the content (lame! file bug reports ;-).
Specifically for people using Baïkal (>= 0.3.3; other Sabre/dav-based solutions will be similar), you can go directly to
https://<Baïkal location>/html/dav.php/
in a browser and get an html interface that allows you to download ics files, and so also allows you to find the right links for those for use with curl/wget.
I tried the accepted answer which did not work for me. With my CalDAV calendar provider I can, however, retrieve all calendar files using
wget -c -r -l 1 -nc --user='[myuser]' --password='[mypassword]' --accept=ics '[url]'
where [myuser] and [mypassword] are what you expect and [url] is the same URL as the one that you enter in your regular CalDAV software (as specified by your provider).
The command creates a directory containing all the ICS-files representing the calendar items. A similar command works for my addressbook.

Mixing CURL with Objective C

I am working with the Let's Crate API, it uses basic Auth and it gives examples on how to use it in CURL:
Takes file and crate_id as
parameters. file is the file data.
E.g. curl -F file=#filename.txt -F
crate_id=123
https://api.letscrate.com/1/files/upload.json
But I have never used CURL before, so how would i make my Mac application when the API involves CURL, I know this is most likely a very simple, question, but I think the fact that I have never used CURL before is confusing me.
I can get it to work using terminal by using this:
curl -u <username:password> -F file=#<filename> -F crate_id=<crate ID(number)> https://api.letscrate.com/1/f
but i want the user to login, and then just click upload and select the file they want, and then send it, nothing overly hard, i just don't know how to get the CURL to play nice with the Objective C.
Thanks in advance, I hope you can help.
You need to use libcurl if you want CURL within an Objective-C application. libcurl is CURL's library and, since it's written in C it plays nicely with Objective-C.