Re: upload example

Giganews Newsgroups
Subject: Re: upload example
Posted by:  Remy Lebeau \(Indy Team\) (re…@lebeausoftware.org)
Date: Wed, 10 Feb 2010

"Quin" <ZuluDa…@hotmail.com> wrote in message
news:B1DF4E7C33A3E340ZuluDa…@hotmail.com...

> I have tried to find how to do this

There are several ways to send data to a server.  Since you control both
client and server, the easiest way is to use the TIdHTTP.Post(TStream)
method on the client side, and the TIdHTTPRequestInfo.PostStream property in
the OnCommandGet event on the server side.  For example:

repeat
    Stream := TFileStream.Create('c:\source\file.jpg', fmOpenRead);
    IdHTTP.Request.ContentType := 'image/jpeg';
    IdHTTP.Post('http://myserver/processjpg', Stream);
    Stream.Free;
until Done;

procedure TForm1.IdHTTPServer1CommandGet(ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
begin
  if ARequestInfo.Document = '/processjpg' then
  begin
    Stream := TFileCreate.Create('c:\dest\file.jpg', fmCreate);
    Stream.CopyFrom(ARequestInfo.PostStream, 0);
    Stream.Free;
    ...
    if (file is ok) then
      AResponseInfo.ResponseNo := 200
    else
      AResponseInfo.ResponseNo := 500;
  end
  ...
end;

--
Remy Lebeau (Indy Team)

Replies

None

In response to

upload example posted by Quin on Mon, 8 Feb 2010