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

Adds a form field representing file data.

procedure AddFile(
    const AFieldName: string; 
    const AFileName: string; 
    const AContentType: string
);
Parameters 
Description 
AFieldName 
Name to be used to reference the field content.
 
AFileName 
File to use as the content of the field.
 
AContentType 
MIME content type represented by the data in the file. 

AddFile is a procedure used to add a content field representing a file to be uploaded as part of the multipart data stream. AddFile creates a TIdFormDataField instance in the internal collection of fields for the multipart data stream. AddFile creates a TFileStream used to read the contents of the file, and AFieldName, AFileName, AContentType, and the file stream to the content field. 

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.