Error in TIdMultiPartFormDataStream

Giganews Newsgroups
Subject: Error in TIdMultiPartFormDataStream
Posted by:  MiaoYang (gmx…@163.com)
Date: Sun, 30 May 2004

Indy(9.0.14), TIdMultiPartFormDataStream cannot generate correct 'multipart
data'

{ I had fixed errors in the IdMultipartFormData.pas }

//...(1) redefine 'const' at
head................................................
  crlf = #13#10;
  sContentType              = 'multipart/form-data; boundary=';
  sContentDisposition_file  = '--%s' + crlf
                              +'Content-Disposition: form-data; name="%s";
filename="%s"' + crlf
                              +'Content-Type: %s' + crlf + crlf;
  sContentDisposition_normal = '--%s' + crlf
                              +'Content-Disposition: form-data; name="%s"' +
crlf + crlf
                              +'%s' + crlf;

//...(2)....................................................................
......
function TIdMultiPartFormDataStream.FormatField(AIndex: Integer): string;

  function FileField(AItem: TIdFormDataField): string;
  begin
    with AItem do begin
      Result :=
Format(sContentDisposition_file,[Boundary,FieldName,FileName,ContentType]);
      { //Old code
        Result := '--' + Boundary + crlf + sContentDisposition + FieldName +
'"' +
        sFileNamePlaceHolder + FileName + '"' + crlf +
        sContentTypePlaceHolder + ContentType;  }
    end;
  end;

  function NormalField(AItem: TIdFormDataField): string;
  begin
    with AItem do begin
      Result :=
Format(sContentDisposition_normal,[Boundary,FieldName,FieldValue]);
      { //Old code
        result := '--' + Boundary + crlf + sContentDisposition + FieldName +
'"' + crlf + crlf +
        FieldValue + crlf;  }
    end;
  end;

begin
  ...

//...(3)....................................................................
......
function TIdMultiPartFormDataStream.PrepareStreamForDispatch: string;
begin
  result := {crlf +} '--' + FBoundary + '--' + crlf;
            { HERE! }
end;

//...(4)....................................................................
......
function TIdFormDataField.GetFieldSize: LongInt;
var
  s : String;
begin
  s:= (Collection as TIdFormDataFields).FParentStream.Boundary;
  if Length(FFileName) > 0 then begin
    FFieldSize :=
Length(Format(sContentDisposition_file,[s,FieldName,FileName,ContentType]));
      //'--' + (Collection as TIdFormDataFields).FParentStream.Boundary
      //+ crlf + sContentDisposition + FieldName + '"' +
sFileNamePlaceHolder + FileName + '"' + crlf
      //+ sContentTypePlaceHolder + ContentType);
  end
  else begin
    FFieldSize :=
Length(Format(sContentDisposition_normal,[s,FieldName,FieldValue]));
      //'--' + (Collection as TIdFormDataFields).FParentStream.Boundary +
      //crlf + sContentDisposition + FieldName + '"' + crlf + crlf +
FFieldValue + crlf);
  end;

Replies