cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Perhaps its not post

From: <man_at_tfhs.net>
Date: Fri, 14 Jul 2006 17:48:53 -0000

On Fri, Jul 14, 2006, Paul Thompson <prtsoft_at_gmail.com> said:

> i believe:
> curl_formadd(&post, &last, CURLFORM_COPYNAME, "datafile", CURLFORM_FILENAME,
> &argv[3], "CURLFORM_END);
>
> This is the correct way to upload a file through post right, assuming the
> server's flag is datafile=file.mp3

if the server calls the field 'datafile', and the filename is given by the
user on the command line, then you have just told curl the field and file
names, but you have not given the body of the file, or told it the content
type. perhaps CURLFORM_FILE is what you mean to use.

i would suggest that you look more closely at the examples that come with
libcurl, and look at the docs a bit more.

allan

>
> On 7/14/06, man_at_tfhs.net <man_at_tfhs.net> wrote:
>>
>> yes. using CURLOPT_HTTPPOST causes curl to do just this, unless you have
>> messed with the content type yourself. have you fixed the incorrect
>> content type on the mp3 file yet?
>>
>> allan
>>
>> On Fri, Jul 14, 2006, Paul Thompson <prtsoft_at_gmail.com> said:
>>
>> > yes, the server replies that it is needed, can curl replicate this?
>> >
>> > On 7/14/06, man_at_tfhs.net <man_at_tfhs.net> wrote:
>> >>
>> >> On Fri, Jul 14, 2006, Paul Thompson <prtsoft_at_gmail.com> said:
>> >>
>> >> > I looked a the header that curl sent and the once the the onlien from
>> >> sent
>> >> > the curl didn't have the ENCTYPE="multipart/form-data", while the
>> online
>> >> one
>> >> > did.
>> >>
>> >> ENCTYPE=X is not an http header. it is part of the <form> tag of an
>> html
>> >> page sent from the server to the client. you used a browser and saw
>> this
>> >> string as part of the transmit from the client to the server?
>> >>
>> >> allan
>> >>
>> >> >
>> >> > On 7/14/06, man_at_tfhs.net <man_at_tfhs.net> wrote:
>> >> >>
>> >> >> the error you are getting is likely misleading. there are multiple
>> >> >> 'content type' settings in a multi-part post, one in the http
>> headers,
>> >> and
>> >> >> one for each 'file' that gets uploaded. curl will set the first
>> >> correctly,
>> >> >> but you must set the others yourself.
>> >> >>
>> >> >> dont set the content type of the mp3 file to multi-part. i bet thats
>> >> your
>> >> >> issue.
>> >> >>
>> >> >> allan
>> >> >>
>> >> >> On Fri, Jul 14, 2006, Paul Thompson <prtsoft_at_gmail.com> said:
>> >> >>
>> >> >> > The message I'm getting back from the server when I'm trying to
>> >> upload
>> >> >> an
>> >> >> > MP3 is :
>> >> >> >
>> >> >> > The following error occurred: Wrong Content-Type. Make sure you
>> have
>> >> >> > included the attribute ENCTYPE="multipart/form-data" in your form.
>> >> >> >
>> >> >> > How do I set this?
>> >> >> >
>> >> >> > Below is my code:
>> >> >> >
>> >> >> >
>> >> >> > #include <stdio.h>
>> >> >> > #include <stdlib.h>
>> >> >> > #include <curl/curl.h>
>> >> >> > char url[] = "
>> pending.sermonaudio.com/winedit_audioadd-aspupload2.asp
>> >> ";
>> >> >> > struct curl_httppost* post = NULL;
>> >> >> > struct curl_httppost* last = NULL;
>> >> >> > struct curl_forms forms[1];
>> >> >> >
>> >> >> > int main (int argc, char *argv) {
>> >> >> > if(argc<=1)
>> >> >> > {
>> >> >> > printf("Sermon Audio Transfer Client - Sermon Upload \n");
>> >> >> > printf("Usage: \n");
>> >> >> > printf("satc-upload-mp3 username password filename sermonid\n");
>> >> >> > return 0;
>> >> >> > }
>> >> >> > CURL *curl;
>> >> >> > CURLcode res;
>> >> >> > curl = curl_easy_init();
>> >> >> >
>> >> >> > /* Add simple name/content section */
>> >> >> > curl_formadd(&post, &last, CURLFORM_COPYNAME, "source",
>> >> >> > CURLFORM_BUFFERPTR, argv[1], CURLFORM_END);
>> >> >> > printf("Added source\n");
>> >> >> > /* Add simple name/content/contenttype section */
>> >> >> > curl_formadd(&post, &last, CURLFORM_COPYNAME, "password",
>> >> >> > CURLFORM_BUFFERPTR, argv[2], CURLFORM_END);
>> >> >> > printf("Added password\n");
>> >> >> > /* Add name/ptrcontent section */
>> >> >> >
>> >> >> >
>> >> >> > /*I have specified that here.....did I do it wrong?*/
>> >> >> >
>> >> >> >
>> >> >> > curl_formadd(&post, &last, CURLFORM_COPYNAME, "datafile",
>> >> >> CURLFORM_FILENAME,
>> >> >> > &argv[3], CURLFORM_CONTENTTYPE, "multipart/form-data",
>> CURLFORM_END);
>> >> >> >
>> >> >> >
>> >> >> > printf("Added datafile\n");
>> >> >> > /* Add name/ptrcontent/contenttype section */
>> >> >> > curl_formadd(&post, &last, CURLFORM_COPYNAME, "SermonID",
>> >> >> > CURLFORM_BUFFERPTR, argv[4], CURLFORM_END);
>> >> >> > /* Set the form info */
>> >> >> > printf("Added sermonid\n");
>> >> >> >
>> >> >> > curl_easy_setopt(curl, CURLOPT_URL, "
>> >> >> > pending.sermonaudio.com/winedit_audioadd-aspupload2.asp");
>> >> >> > curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
>> >> >> > curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
>> >> >> > res = curl_easy_perform(curl);
>> >> >> > printf("%d", res);
>> >> >> >
>> >> >> >
>> >> >> > return 0;
>> >> >> >
>> >> >> > }
>> >> >> >
>> >> >> > I apologize if you get two emails, I wasn't subscribed the first
>> time
>> >> so
>> >> >> I
>> >> >> > don't know if it went through.
>> >> >> >
>> >> >> > --
>> >> >> > P.S: this is what the alphabet would look like with Q and R
>> removed!
>> >> :)
>> >> >> >
>> >> >>
>> >> >> --
>> >> >> m. allan noah
>> >> >> IT Director, TfHS.net
>> >> >> ph# (804) 355-5489
>> >> >> tf# (866) 724-9722
>> >> >> fx# (804) 355-0477
>> >> >>
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >> > --
>> >> > P.S: this is what the alphabet would look like with Q and R removed!
>> :)
>> >> >
>> >>
>> >> --
>> >> m. allan noah
>> >> IT Director, TfHS.net
>> >> ph# (804) 355-5489
>> >> tf# (866) 724-9722
>> >> fx# (804) 355-0477
>> >>
>> >>
>> >>
>> >
>> >
>> > --
>> > P.S: this is what the alphabet would look like with Q and R removed! :)
>> >
>>
>> --
>> m. allan noah
>> IT Director, TfHS.net
>> ph# (804) 355-5489
>> tf# (866) 724-9722
>> fx# (804) 355-0477
>>
>>
>>
>
>
> --
> P.S: this is what the alphabet would look like with Q and R removed! :)
>

-- 
m. allan noah
IT Director, TfHS.net
ph# (804) 355-5489
tf# (866) 724-9722
fx# (804) 355-0477
Received on 2006-07-14