cURL / Mailing Lists / curl-library / Single Mail

curl-library

perl and formadd()

From: TEXTORIS Julien <julien.textoris_at_gmail.com>
Date: Thu, 25 Aug 2005 06:27:10 +0200

Hi,

I'm trying to write a perl script to upload pictures to a development
site, because for linux users, there is no other solution provided than
uploading each picture one by one.

There is not a lot of help on WWW::Curl::easy on perl's pages, so i read
liburl's pages, which tell to see the C/C++ description for example.

What i want to write is a multipart form post, in C there is an example
like that :

    struct curl_httppost *post=NULL;
    struct curl_httppost *last=NULL;

    curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END);
    curl_formadd(&post, &last, CURLFORM_COPYNAME, "project",
CURLFORM_COPYCONTENTS, "curl", CURLFORM_END);
    curl_formadd(&post, &last, CURLFORM_COPYNAME, "logotype-image",
CURLFORM_FILECONTENT, "curl.png", CURLFORM_END);

    /* Set the form info */
    curl_easy_setopt(easyhandle, CURLOPT_HTTPPOST, post);

    curl_easy_perform(easyhandle); /* post away! */

    /* free the post data again */
    curl_formfree(post);

I "translate" this like that for perl :

    my $post = NULL;
     my $last = NULL;
     $curl->formadd(\$post,\$last,CURLFORM_COPYNAME, "fuseaction",
CURLFORM_COPYCONTENTS, "importer", CURLFORM_END);
     $curl->formadd(\$post,\$last,CURLFORM_COPYNAME, "flag",
CURLFORM_COPYCONTENTS, "creeralbum", CURLFORM_END);
     $curl->formadd(\$post,\$last,CURLFORM_COPYNAME, "from",
CURLFORM_COPYCONTENTS, "album", CURLFORM_END);
     $curl->formadd(\$post,\$last,CURLFORM_COPYNAME, "inscr",
CURLFORM_COPYCONTENTS, "1", CURLFORM_END);
     $curl->formadd(\$post,\$last,CURLFORM_COPYNAME, "pc",
CURLFORM_COPYCONTENTS, "", CURLFORM_END);
     $curl->formadd(\$post,\$last,CURLFORM_COPYNAME, "album_name",
CURLFORM_COPYCONTENTS, $album_name, CURLFORM_END);
     $curl->formadd(\$post,\$last,CURLFORM_COPYNAME, "name",
CURLFORM_COPYCONTENTS, "userfile1", CURLFORM_END);
     $curl->formadd(\$post,\$last,CURLFORM_COPYNAME, "filename",
CURLFORM_COPYCONTENTS, $_, CURLFORM_END);
     $curl->formadd(\$post,\$last,CURLFORM_COPYNAME, "image/jpeg",
CURLFORM_FILECONTENT, $path_dir.$_, CURLFORM_END);
     $curl->setopt(CURLOPT_HTTPPOST, $post);
    
       if ($curl->perform() != 0) {
          print "Failed ::".$curl->errbuf."\n";
       }
       else {print "\n-------------- Créé l'album et upload $_\n";}

     $curl->formfree($post);

When i use "strict" module (use strict), i got this error :

Bareword "CURLFORM_COPYNAME" not allowed while "strict subs" in use at
mypix.pl line 118.
Bareword "CURLFORM_COPYCONTENTS" not allowed while "strict subs" in use
at mypix.pl line 118.
Bareword "CURLFORM_END" not allowed while "strict subs" in use at
mypix.pl line 118.

So i tried without it to test and i got a segfault !
 
My problem is that i don't know in fact if these fonction are
implemented for perl :

$curl->formadd...
$curl->formfree...

and I haven't find a precise documentation on it, so as i'm quite a
newbie with curl, i'm quite lost.

Would you understand where the error come from, and/or know where i can
find a more precise documentation for perl ?

Thanks in advance

Julien
Received on 2005-08-25