본문 바로가기
Delphi Tip/인터넷

indy idhttp 이용해서 파일 업로드

by MonoSoft 2021. 11. 19.
728x90
반응형

indy idhttp 이용해서 파일 업로드

 

IdMultipartFormData 을 uses절에 추가할것 

 

==============================================

uses IdMultipartFormData;

procedure TForm1.Button1Click(Sender: TObject);

var

  UploadFile: TIdMultiPartFormDataStream;

  Outputs: TStringStream;

begin

  if OpenDialog1.Execute then

  begin

    UploadFile := TIdMultiPartFormDataStream.Create;

    Outputs := TStringStream.Create('');

 

    try

      IdHTTP.Request.ContentType := UploadFile.RequestContentType;

      UploadFile.AddFormField('Mb_Num', '13');

      UploadFile.AddFile('UploadList', OpenDialog1.FileName, 'application/unknown');

      UploadFile.Position := 0;

 

      try

        IdHTTP.Post( 'http://www.xxxxx.com/xxxx.asp', UploadFile, Outputs);

      except

        ShowMessage('포스트 에러');

      end;

 

      ShowMessage( Outputs.DataString );

    finally

      UploadFile.Free;

      Outputs.Free;

    end;

  end;

end;

 

728x90
반응형

댓글