Topic Path: Symbol Reference > Classes > TIdMultiPartFormDataStream Class > TIdMultiPartFormDataStream Methods > AddFormField Method
ContentsIndexHome
PreviousUpNext
TIdMultiPartFormDataStream.AddFormField Method
procedure AddFormField(
    const AFieldName: string; 
    const AFieldValue: string
);
Parameters 
Description 
AFieldName 
Name of the content field.
 
AFieldValue 
Value of the content field. 

AddFormField is a procedure used to add a named content field with a given value to the multipart data stream. AFieldName contains the name to assign to the content field. AFieldValue contains the value for the content field. 

AddFormField create a TIdFormDataField instance in the internal collection used for form fields. Te values indicated in AFieldName and AFieldValue are assigned to the FieldName and FieldValue properties. 

AddFile updates the Size property to include the size of any exisiting content fields and the size of the newly added content field (including headers). 

(Delphi) Adding an upload file to a multipart data stream. 

 

  AValues := TIdStringList.Create;

  AValues.Values['usr'] := '"John Doe" ';
  AValues.Values['grp'] := 'public';
  AValues.Values['fil'] := 'c:imageslogo.gif';

  PostStream:= TIdMultiPartFormDataStream.Create;
  ResponseStream := TIdStringStream.Create('');

  try
    PostStream.AddFormField('usr', AValues.Values['usr']);
    PostStream.AddFormField('grp', AValues.Values['grp']);

    PostStream.AddFile('fil', AValues.Values['fil'],
      GetMIMETypeFromFile(AValues.Values['fil']));

    IdHTTP1.Request.ContentType := PostStream.RequestContentType;
    IdHTTP1.Post(sURL, PostStream, ResponseStream);
  finally
    Memo1.Text := ResponseStream.DataString;
    ResponseStream.Free;
    PostStream.Free;
    AValues.Free;
  end;
Copyright 1993-2006, Chad Z. Hower (aka Kudzu) and the Indy Pit Crew. All rights reserved.
Post feedback to the Indy Docs Newsgroup.