Re: multipart form data not working with files

Giganews Newsgroups
Subject: Re: multipart form data not working with files
Posted by:  Remy Lebeau (Indy Team) (no.spam@no.spam.com)
Date: Fri, 14 Sep 2007

"Cameron Hart" <ne…@news.co.nz> wrote in message
news:5CBC59506935E340ne…@news.co.nz...

> When using TIdMultipartformdata there is a problem if
> you add a file field which is not the first field in the form.

The ordering of the fields makes no difference.  Each one is formatted
individually when transmitted.

> The multipart form is cleared and then the file data is added.
> for example add a "username" field, a "password" field, and
> then a file field and during output of the data to HTTP stream
> it only contains the file data.  the other fields are overwritten.

Please show an actual example, as well as the raw data being produced by it.

> This problem is caused by the use of TIdStreamHelper.ReadBytes
> in TIdMultiPartFormDataStream.IdRead to write the file stream
> to the multipart form data stream.

Please be more specific.  What is the actual problem with it?

> i have gone for an easy fix because i dont want to change ReadBytes
> without knowing what it affects.  I have instead read the file into
> FInternalBuffer and then copied to VBuffer by using CopyTIdBytes

What you have done manually is functionally similar to what ReadBytes()
already does internally.

> the following code is from TIdMultiPartFormDataStream.IdRead.  note the
> commented line is change to the following 2 lines.

    //LCount := TIdStreamHelper.ReadBytes(FInputStream,VBuffer, ACount -
LTotalRead, LBufferCount);

    LCount := TIdStreamHelper.ReadBytes(FInputStream,FInternalBuffer,
ACount - LTotalRead, 0);
    CopyTIdBytes(FInternalBuffer, 0, VBuffer, LBufferCount, LCount);

> I am hoping someone responsible for Indy can verify that this
> code works or provide alternative code.

Please explain why you think the original code was problematic in the first
place.  We don't blindly throw in "fixes" without first understanding what
is being "fixed".

Gmbit

Replies

In response to

multipart form data not working with files posted by Cameron Hart on Fri, 14 Sep 2007