Solved

Upload with Indy

Posted on 2006-07-19
5
584 Views
Last Modified: 2010-04-05
I need the code to upload with Indy. If possible I want to upload a TStringList without saving it in a temp file ?

Thanks
0
Comment
Question by:crystyan
  • 4
5 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17143018
upload to where? TCP Client to TCP Server?
or to a Web server?

- tcp client side indy 9 -

TCPClient1.WriteInteger(mystringlist.count); // send the # of lines to teh server
for i := 0 to pred(mystringlist.count) do // loop through each line and send them 1 at a time
begin
    TCPClient1.WriteLn(mystringlist[i]); // send 1 line
end;

- tcp server side indy 9 -

var
    i: integer;
    newstringlist: tstringlist;
begin
    newstringlist := tstringlist.create;
    try
        numlines := AThread.Connection.ReadInteger;
        for i := 1 to numlines do
            newstringlist.Add(AThread.Connection.ReadLn);

// do something with the stringlist now

    finally
        newstringlist.free;
    end;



- tcp client side indy 10.0.52 -

TCPClient1.IOHandler.WriteInteger(mystringlist.count); // send the # of lines to teh server
for i := 0 to pred(mystringlist.count) do // loop through each line and send them 1 at a time
begin
    TCPClient1.IOHandler.WriteLn(mystringlist[i]); // send 1 line
end;

- tcp server side indy 10.0.52 -

var
    i: integer;
    newstringlist: tstringlist;
begin
    newstringlist := tstringlist.create;
    try
        numlines := AContext.Connection.IOHandler.ReadInteger;
        for i := 1 to numlines do
            newstringlist.Add(AContext.Connection.IOHandler.ReadLn);

// do something with the stringlist now

    finally
        newstringlist.free;
    end;
0
 

Author Comment

by:crystyan
ID: 17143023
on a webserver.
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17143248
The Indy 9 chat demo is very buggy
firstly, the client can lock up on the
Msg := IdTCPClient1.ReadLn('', 5);
line in the Timer1Timer() event

This can be resolved by putting a TIdAntiFreeze on the form, but you still get a memory leak
(just watch the task maanger while your client is connected)
To resolve this you need to disable the TTimer while doing the ReadLn, so your Timer1Timer routine ends up looking something like this :-

procedure TForm1.Timer1Timer(Sender: TObject);
var
  Com,
  Msg : String;
begin
  if not IdTcpClient1.Connected then
    exit;
  Timer1.Enabled := False;
  try
    Msg := IdTCPClient1.ReadLn('', 5);

    if Msg <> '' then
      if Msg[1] <> '@' then
        begin
        { Not a system command }
          memLines.Lines.Add(Msg);
        end
      else
        begin
        { System command }
          Com := UpperCase(Trim(Copy(Msg, 2, Pos(':', Msg) -2)));
          Msg := UpperCase(Trim(Copy(Msg, Pos(':', Msg) +1, Length(Msg))));
          if Com = 'CLIENTS' then
            lbClients.Items.CommaText := Msg;
        end;
    finally
      Timer1.Enabled := True;
    end;
  end;

anyway, this may be the cause of your problems...
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17143272
OOPS, sorry, ignore the above post, it was meant for another question ... my bad :-(
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 250 total points
ID: 17143305
use a TStringStream, and upload it as a stream
I thi nk it's something like :-
  var
    MyStream: TStringStream;
  begin
    MyStream := TStringStream.Create(Memo1.Lines.Text);
    try
      idhttp1.Put('http://www.someserver.com', MyStream)
    finally
      MyStream.Free;
    end;
  end;
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question