new CurlFile in Harbour

955 views
Skip to first unread message

Victor Casajuana Mas

unread,
Apr 22, 2020, 10:43:39 AM4/22/20
to Harbour Users
Hello Group!.

I'm in a project that's need send files to prestashop API. I can do with php:
$args['image'] = new CurlFile($image_path, $image_mime);

    $ch = curl_init();
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
   curl_setopt($ch, CURLOPT_URL, $urlImage);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_USERPWD, $key.':');
   curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
   $result = curl_exec($ch);


but in harbour I don't exists the CurlFile class for a create a curlfile objetc to send with 
curl_easy_setopt( curl, HB_CURLOPT_POSTFIELDS,      oFile)


Does anyone know how to do it?

Thanks and take care!

mstuff kstuff

unread,
May 8, 2020, 10:34:45 AM5/8/20
to Harbour Users
Victor,

Harbour 3.4 has 2  examples of using curl in the contrib directory.
hbcurl: An email and a ftp program.


Mike

Victor Casajuana Mas

unread,
May 10, 2020, 5:55:31 AM5/10/20
to Harbour Users
Yes Mike.
I use curl on harbour, but I need the CurlFile() function. This function does not exist in the curl contribution by Viktor Szakats, but in PHP it does exist: https://www.php.net/manual/en/class.curlfile.php

Gerald Drouillard

unread,
May 10, 2020, 11:06:03 AM5/10/20
to harbou...@googlegroups.com
When you are googling look for examples of curl command line.  Once you get it working in a script or batch file then the Harbour part should be easy.

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/f8cd1772-b911-40de-afdc-b4054c4122f9%40googlegroups.com.

Anupam

unread,
May 11, 2020, 6:29:20 AM5/11/20
to Harbour Users
Hello Gerald,

This below curl working with command line with bat file...how can we use with harbour. 

curl -X POST https://content.dropboxapi.com/2/files/upload --header "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxx"  --header "Dropbox-API-Arg: {\"path\": \"/Homework/test.pdf\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}"  --header "Content-Type: application/octet-stream"  --data-binary @test.pdf


Best Regards,
Anupam

victorcas...@gmail.com

unread,
Sep 25, 2020, 2:16:01 PM9/25/20
to Harbour Users
Thank you, my intention is not to use the command line, but harbour does not have the CurlFile() class

Gerald Drouillard

unread,
Sep 25, 2020, 3:00:04 PM9/25/20
to harbou...@googlegroups.com
Attached is what we use to interface with curl.

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
libcurl.prg

Victor Casajuana Mas

unread,
Feb 6, 2021, 4:28:00 AM2/6/21
to Harbour Users
Hello!
Thanks for the libcurl.prg it's very complete.
I'm now testing this question, it's simply but don't function.
I need to upload a file with curl to url with form. In command line runs fine, but I can't translate to harbour curl

This comand works fine:
curl.exe -u <pasword>:<password> -F "image=@file.jpg" http://www.urltoupload.com

I translate to HB Curl:

       curl_global_init()
   hCurl := curl_easy_init()
       curl_easy_setopt( hCurl, HB_CURLOPT_URL,                   'http://www.urltoupload.com' )
   curl_easy_setopt( hCurl, HB_CURLOPT_RETURNTRANSFER,        1 )
   curl_easy_setopt( hCurl, HB_CURLOPT_POST,                  1 )
   curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS,            'image=@file.jpg '  ) 
   curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD,               '<password>:<password>' )

   nResult := curl_easy_perform( hCurl )

nResult always return 23 (HB_CURLE_WRITE_ERROR)

any ideas?

Thanks!!!

Gerald Drouillard

unread,
Feb 6, 2021, 7:41:52 AM2/6/21
to harbou...@googlegroups.com

   curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS,            'image=@file.jpg '  ) 
Maybe remove the trailing space after the .jpg and the closing quote? 

Gerald Drouillard

unread,
Feb 6, 2021, 7:43:51 AM2/6/21
to harbou...@googlegroups.com
Also, enable debugging in the curl.exe command (it will produce a nice log file of what it is doing). Then compare it to the log file in the harbour version.

Lewis Bell

unread,
Feb 6, 2021, 10:01:07 PM2/6/21
to harbou...@googlegroups.com
==> Linking D:\Progamacion\Proyectos\SiGa2\Pos64.exe ...
    GCC -Wall -mwindows -m64 -static SCRIPT_FILE -o
D:\Progamacion\Proyectos\SiGa2\Pos64.exe
    Error:
:\Progamacion\OOHG64\lib\hb\mingw64\libLIBJOSE_64.a(Libreria.o):Libreria.c:(.data+0x2c90):
undefined reference to `HB_FUN_ARRAYRDD'

==> Build status: ERROR

Victor Casajuana Mas

unread,
Feb 7, 2021, 1:20:41 AM2/7/21
to Harbour Users
‎está bien, el espacio no existe en la prueba. Gracias‎

Victor Casajuana Mas

unread,
Feb 7, 2021, 1:33:10 AM2/7/21
to Harbour Users
I enable debugging in curl.exe command and see more info, thanks for idea, but I don't know how activate log in harbour curl, y try this:

curl_easy_setopt( hCurl, HB_CURLOPT_DEBUGDATA, 'debug.txt', .T. )

but debug.txt don't created

then I try this also:

curl_easy_setopt( hCurl, HB_CURLOPT_DEBUGBLOCK, {|a,b,c,d,e,f| libcurl_trace(a,b,c,d,e,f ) },.t.)

libcurl_trace() never calls, how can I save the log in curl harbour?

Thansk a lot!!

Lewis Bell

unread,
Feb 7, 2021, 9:19:46 PM2/7/21
to harbou...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages