multipart/form-data: Parsing PostStream

Giganews Newsgroups
Subject: multipart/form-data: Parsing PostStream
Posted by:  Christian Kaufmann (christian.kaufma…
Date: Mon, 15 Feb 2010


I have to say, this is a nightmare...

I'm still working on parsing a multipart/form-data stream and have the
following problems:

1) What is the save way to see the difference between the content of
an edit control or a file upload?
- Do I have to "know" it?
- Can I rely on the field filename?

In my old code I checked for the Content-Type header. Only file
uploads had such a header. But when I set the charset in an TIdHttp
client, then also text fields get this header.

2) Encoding by webbrowsers: I only tested with Firefox 3.5 until know.
The only information I get from there is in
ARequestInfo.AcceptCharset. The value is

This is independent if the html file is Ansi or Utf-8 and I didn't
find an attribute to set / force e.g. Utf-8.

My examples for headers:

Content-Disposition: form-data; name="Data"
Content-Type: text/plain; charset="UTF-8"

From TIdHttp when using AddFormField

Content-Disposition: form-data; name="Data"

The form field header from FireFox.

Content-Disposition: form-data; name="ResultFile";
Content-Type: application/octet-stream

Content-Disposition: form-data; name="ResultFile";
Content-Type: text/plain

Examples for form file upload header from FireFox.

cu Christian