curl / Mailing Lists / curl-users / Single Mail

curl-users

Re: Upload image to server Libcurl c++

From: Avi <avi.pars_at_gmail.com>
Date: Thu, 16 Feb 2017 13:46:53 +0000

Oh. Can you refer me to the correct mailing list? I do use and love the
curl tool, but this does apply to libcurl. I thought it was ran by the
smart group.

On Thu, Feb 16, 2017, 1:10 PM Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Thu, 16 Feb 2017, Avi wrote:
>
> You rather want to use the curl-library mailing list for libcurl stuff,
> that's
> the list for libcurl users and hackers. This list is more for the users of
> the
> curl tool.
>
> > I want to upload an image from a user's computer to my server.
> > I used an app called postman to help me, I successfully got results from
> > postman, it generates code for you, I got it to work with CMT curl:
> > curl -X POST -H "Cache-Control: no-cache" -H "Postman-Token:
> > fb42cc8e-63dc-a079-9889-35088dd7f637" -H "Content-Type:
> > multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -F
> > "imagefile=@duck.jpg" "http://0.0.0.0:5000/testJsonclassify_upload"
>
> That's a questionable use of curl (and feel free to report that to postman
> if
> that's what generated it). Why set the Content-Type like that? Remove that
> part and it becomes a much better command line. Oh, and remove "-X POST" as
> well while you're at it, it will only bring you tears. (I presume your URL
> using 0.0.0.0 is made up.)
>
> > curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
>
> Remove this.
>
> > headers = curl_slist_append(headers, "content-type: multipart/form-data;
> > boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
>
> Remove this.
>
> > curl_easy_setopt(hnd, CURLOPT_POSTFIELDS,
> > "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition:
> form-data;
> > name=\"imagefile\"; filename=\"duck.jpg\"\r\nContent-Type:
> > image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");
>
> Don't do that. Use curl_formadd() instead and add each section one by one,
> which is what the curl -F option does. See the multi-post.c example:
> https://curl.haxx.se/libcurl/c/multi-post.html
>
> --
>
> / daniel.haxx.se
> -----------------------------------------------------------
> Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
> Etiquette: https://curl.haxx.se/mail/etiquette.html
>

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-02-16