cURL post file

309 views
Skip to first unread message

Aleksandar Ilic

unread,
Jan 16, 2013, 5:29:33 AM1/16/13
to harbou...@googlegroups.com
Hi,

Does anyone have an example how to post file with post fields (using cURL)?

Currently, I'm using this piece of code for POST requests:

curl := curl_easy_init()

curl_easy_setopt(curl, HB_CURLOPT_URL, "http://localhost/test/post.php")

curl_easy_setopt(curl, HB_CURLOPT_POST, .T.);
curl_easy_setopt(curl, HB_CURLOPT_POSTFIELDS, "param1=value1&param2=value2);

? curl_easy_perform(curl)

curl_easy_cleanup(curl)


I'm not able to find any working example how to attach file to this post request.

As I can see, this is intended for other purposes (mail attachment, etc.)

curl_easy_setopt(curl, HB_CURLOPT_UL_FILE_SETUP, "file_to_send.ext")
curl_easy_setopt(curl, HB_CURLOPT_INFILESIZE, hb_FSize(
"file_to_send.ext"))

Any help is appreciated!

Regards,
Aleksandar

Aleksandar Ilic

unread,
Jan 16, 2013, 10:22:10 AM1/16/13
to harbou...@googlegroups.com
Here's the answer.

In order to attach file, we need to set this cURL option:

curl_easy_setopt(curl, HB_CURLOPT_HTTPPOST, {{"file", "file_to_send.ext"}});

This should be documented somewhere.

Regards, AI

Aleksandar Ilic

unread,
Jan 16, 2013, 2:57:35 PM1/16/13
to harbou...@googlegroups.com
Well, we cannot combine HB_CURLOPT_HTTPPOST and HB_CURLOPT_POSTFIELDS, so we are again at the beginning. One is excluding the other one.

There's a patch, but not included:
http://sourceforge.net/tracker/?func=detail&aid=3285144&group_id=681&atid=100681

Any help is kindly appreciated.

Regards, AI

har...@syenar.net

unread,
Jan 16, 2013, 3:16:46 PM1/16/13
to harbou...@googlegroups.com
Follow-up:
https://groups.google.com/d/msg/harbour-devel/r7EEWaOrY9k/6AShHFsdiEAJ
https://groups.google.com/d/msg/harbour-devel/-Kv3sHXGQRw/Z3qi78up2KAJ

If there exists a capable programmer who can fix the showstopper 
problem in the last version as in repository, such patch can be 
committed anytime.

-- Viktor
Reply all
Reply to author
Forward
0 new messages