cURL / Mailing Lists / curl-library / Single Mail

curl-library

Setting content type of uploaded file using CURLFORM_CONTENTTYPE

From: Michael Wood <esiotrot_at_gmail.com>
Date: Tue, 12 Oct 2010 11:58:24 +0200

Hi

I'm using libcurl 7.19.7 on Ubuntu and I'm trying to set the content
type of an uploaded file using CURLFORM_CONTENTTYPE, but it does not
appear to be working.

I've tried modifying the example postit2.c to add the content type to
application/octet-stream, but it still seems to be using text/plain.
I haven't tried a later version of libcurl yet and I will do that, but
am I doing something wrong? I've had a look at the tests in git and I
don't see any that try to use CURLFORM_CONTENTTYPE.

--- postit2.orig 2010-10-12 11:31:55.149408811 +0200
+++ postit2.c 2010-10-12 11:39:08.100329459 +0200
@@ -45,6 +45,7 @@
                &lastptr,
                CURLFORM_COPYNAME, "sendfile",
                CURLFORM_FILE, "postit2.c",
+ CURLFORM_CONTENTTYPE, "application/octet-stream",
                CURLFORM_END);

   /* Fill in the filename field */
@@ -68,7 +69,8 @@
   headerlist = curl_slist_append(headerlist, buf);
   if(curl) {
     /* what URL that receives this POST */
- curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi");
+ curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/cgi-bin/test.cgi");
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) )
       /* only disable 100-continue header if explicitly requested */
       curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);

Here's the verbose output:

* About to connect() to localhost port 80 (#0)
* Trying ::1... * Connection refused
* Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> POST /cgi-bin/test.cgi HTTP/1.1
Host: localhost
Accept: */*
Content-Length: 3290
Expect: 100-continue
Content-Type: multipart/form-data;
boundary=----------------------------7d8f5c826a96

< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Date: Tue, 12 Oct 2010 09:48:57 GMT
< Server: Apache/2.2.14 (Ubuntu)
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/plain
<
Got it
* Connection #0 to host localhost left intact
* Closing connection #0

Thanks.

-- 
Michael Wood <esiotrot_at_gmail.com>
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-10-12