Topic Path: Symbol Reference > Classes > TIdMultiPartFormDataStream Class > TIdMultiPartFormDataStream Methods > AddObject Method
ContentsIndexHome
PreviousUpNext
TIdMultiPartFormDataStream.AddObject Method

Adds a form field representing data with a specific content type.

procedure AddObject(
    const AFieldName: string; 
    const AContentType: string; 
    AFileData: TObject; 
    const AFileName: string = ''
);
Parameters 
Description 
AFieldName 
Name to be used to reference the field content.
 
AContentType 
MIME content type represented by the data in the file.
 
AFileData 
Object with the content for the form field.
 
AFileName 
File associated with the field data. 

AddObject is a procedure used to add a form field to the multipart data stream where the content is stored in AFileData. AddObject creates a TIdFormDataField instance in the internal collection of fields for the multipart data stream. AddObject assigns the values in AFieldName, AFileName,AContentType, and AFileData to the form field. 

AddObject 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.