cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: problem with multipart/form-data

From: Daniel Fairchild <drxl_at_gmx.net>
Date: Tue, 21 Jun 2005 00:17:44 +0200

Please excuse me for not being able to make myself more clear.
I'll try it again.
We have a text file "greeting.txt" containing the line "hello world"

When it is submited through a html <input type="file"> field it is
represented as follows in the http request:

-----------------------------7d5f3216040c
Content-Disposition: form-data; name="FILE1"; filename="greeting.txt"
Content-Type: text/plain

hello world
-----------------------------7d5f3216040c

The entry would have been near identical except from the "hello world"
part if the file had been empty. As you state libcurl supports both
empty and non-empty files submission very well.
What I don't think it supports is the http request entry for a <input
type=file > element that was left "empty" (not pointing to a file in the
local file system).
The look like this:
Notice that the "name" value stays the same but "filename" is empty and
the "Content-Type" is application/octet-stream

-----------------------------7d50316040c
Content-Disposition: form-data; name="FILE1"; filename=""
Content-Type: application/octet-stream

-----------------------------7d50316040c

Daniel Stenberg wrote:

> On Mon, 20 Jun 2005, Daniel Fairchild wrote:
>
>
>> Notice that even though no data was submitted to the input file
>> field, there's still something about the file input in the http request.
>
>
> I don't understand. What do you mean with this last line?
>
That <input type="file" name="something"> leaves two kinds of entries in
the http request (empty and submitted, and that only one of them seems
to be supported) submitted.

>> Please note that I have no problems when actually supplying a file
>> with libcurl,
>
>
> So what _is_ the problem?

When I don't supply a file but still want to fill out the "http request"
according to what the server expects.

>> ($post_data[FILE1] = "@pathtofile";) to the form on the server in
>> question.
>
>
> Now you talk PHP/CURL I presume?

Yes, I believe so.

>> When I'm setting up my post data array (to be submitted to libcurl
>> with curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );) I'd like to
>> be able to add the result of empty html file forms to the http request.
>
>
> You want to post an empty file? So what goes wrong if you do submit an
> empty file? It seems to work fine when I try it.
>
Not an empty file. An empty file would leave both a "filename" path and
set the Content-Type to something that is probably different from
"application/octet-stream". And in this case the empty file would
overwrite an exsisting file. The server in question leaves the exsisting
file alone if no new data was submitted.

>> I'm thinking that maybe an entry like this:
>> $post_data[FILE1] = "@";
>
>
> Now you're talking PHP/CURL again. It could probably be made to
> support that syntax, but you're talking to the wrong crowd if you want
> to discuss what PHP/CURL should or should not do since we don't
> maintain nor deal with that binding here. It is authored by the PHP team.

Well I was thinking that since this way of handling <input type="file">
seems to be so universal for browsers, then CURL in general might want
to support this entry type in "HTTP requests".

Personally I'd be perfectly happy if only the php cURL libraries would
let me supply my own HTTP requests without interference, but it messes
them up somehow. I get the exact behaviour described here:
http://dk2.php.net/manual/en/ref.curl.php#22857
It works on my own test apache server, but messes up on the microsoft
server I'm trying to communicate with.

Does writing your own http requests work better with other versions of cURL?

best regards
Daniel Fairchild
Received on 2005-06-21