cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Multi-Part form with blank filenames.

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Tue, 16 Sep 2003 13:02:05 +0200 (CEST)

On Mon, 15 Sep 2003 swdlst_at_indoorstorm.com wrote:

> I am trying to post a form that is giving me trouble. Its a multi part with
> multiple image uploads. The problem happens when I leave one of the optional
> image fields blank.
>
> Curl produces something like this.

> c:\curl\curl.exe --url "http://testserver/test.pl" -F "img1=@1x1.gif" -F
> "img2="

The thing is here, that you don't mark the 'img2' as a file upload. It is just
a "normal" part with the name 'img2' and no contents. curl adds no file name
field for "normal" parts.

> ------------------------------f27aeac4ef31
> Content-Disposition: form-data; name="img2"
>
>
> Both Netscape and IE produce something like this.
>
> -----------------------------297751839010082

Is this separator from Netscape? I used some real-world separators from IE as
inspiration when I remade the curl ones to look like above.

> Content-Disposition: form-data; name="img2"; filename=""
> Content-Type: application/octet-stream
>
> The server is IIS/.aspx so im sure thats why there is a problem, but it
> seems like curl should do the same as a browser.

The file name field is absent because you didn't mark the field as a file
name. And if you try to use a non-existing file name, curl will return an
error... I think creating an empty file is the only way to do this, unless you
use libcurl directly.

> -F "img1=@;type=application/octet-stream"

The "Content-Type:" header is not mandatory and I bet the different browsers
will use this header differently. I have been pondering about using the
"application/octet-stream" type as an internal default but I've been
hesitating to do that because the current approach has been proved to work for
many years. Multipart formpost receivers are often very naive in their parsing
(judgement based on experience), and I'd hate to break functionality with
servers that work today.

-- 
 Daniel Stenberg -- curl: been grokking URLs since 1998
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-09-16