Internet Direct (Indy)
Home
PreviousUpNext
TIdMultiPartFormDataStream.AddObject Method

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

Pascal
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;
Internet Direct (Indy) version 10.1.5
Copyright © 1993-2006, Chad Z. Hower (aka Kudzu) and the Indy Pit Crew. All rights reserved.
Website http://www.indyproject.org.
Post feedback to the Indy Documentation newsgroup.