[DUG] HTTP Upload Progress
Conor Boyd
Conor.Boyd at trimble.co.nz
Thu Sep 18 08:14:01 NZST 2008
Here's my reply to your original request earlier in the week.
I've used the Indy library that comes with Delphi to do HTTP uploads
with progress notification. Works quite well.
E.g.
FHTTPClient := TIdHTTP.Create(nil);
with FHTTPClient do begin
ProxyParams.ProxyServer:= ProxyHost;
ProxyParams.ProxyPort := ProxyPort;
ProxyParams.ProxyUsername := ProxyUsername;
ProxyParams.ProxyPassword := ProxyPassword;
OnWork := HTTPWorkEvent;
OnWorkBegin := HTTPBeginWorkEvent;
OnWorkEnd := HTTPEndWorkEvent;
end;
I use it to upload a JPEG to a webserver running Gallery
(http://gallery.menalto.com/) as follows:
function TGalleryHelper.AddImage(const AlbumID: Integer; const Image:
TStream; const ImageFilename, Caption, Description, Summary: String):
TGalleryStatus;
var
Command: String;
Response: String;
ImageStream: TIdMultipartFormDataStream;
begin
...
ImageStream := TIdMultiPartFormDataStream.Create;
try
ImageStream.AddFormField('g2_form[cmd]', 'add-item');
ImageStream.AddFormField('g2_form[protocol_version]', Format('%f',
[PROTOCOL_VERSION]));
ImageStream.AddFormField('g2_form[set_albumId]', Format('%d',
[AlbumID]));
ImageStream.AddFormField('g2_form[caption]', Caption);
ImageStream.AddFormField('g2_form[force_filename]',
ImageFilename);
ImageStream.AddFormField('g2_form[extrafield.Summary]', Summary);
ImageStream.AddFormField('g2_form[extrafield.Description]',
Description);
ImageStream.AddObject('g2_userfile', 'image/jpeg', Image,
ImageFilename);
Response := FHTTPClient.Post(Command, ImageStream);
finally
ImageStream.Free;
end;
...
The events that the TIdHTTPClient class raises can be handled as
follows:
procedure TGalleryHelper.HTTPBeginWorkEvent(Sender: TObject; AWorkMode:
TWorkMode; const AWorkCountMax: Integer);
begin
// Do something with AWorkCountMax, e.g. set the max value on a
progress bar.
end;
procedure TGalleryHelper.HTTPEndWorkEvent(Sender: TObject; AWorkMode:
TWorkMode);
begin
// You're all done.
end;
procedure TGalleryHelper.HTTPWorkEvent(Sender: TObject; AWorkMode:
TWorkMode; const AWorkCount: Integer);
begin
// Do something with AWorkCount, e.g. set the progress value of a
progress bar.
end;
I have all this running in a thread to keep my GUI nice and responsive
while the upload is happening.
HTH, if you've more questions, let me know.
Conor
________________________________
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
On Behalf Of Jeremy Coulter
Sent: Thursday, 18 September 2008 6:49 a.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] HTTP Upload Progress
yeah there is a bit of stuff around done in Java, but the last thing we
need to have to do is explain to people how to install java. The same
for flash, which is why I was heading in the native code direction.
Jeremy
________________________________
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
On Behalf Of Richard Vowles
Sent: 18 September 2008 05:46
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] HTTP Upload Progress
The way I implemented this (in a Java web server) was that once the form
was submitted, an ajax request was fired off in the background and
repeatedly asked the server how the file upload was progressing, and
updated the amount of colour in a progress bar. The upload was attached
to the session, so the ajax call was able to grab the info structure
from the session and query it (as the file upload specifies how big
something is and as the upload is happening, you can just specify in the
structure how much you had received).
2008/9/17 Jeremy Coulter <jscoulter at gmail.com>
Hi Al, sorry this is a repeated post, as I have not received any
emails from the list in a week, then I got an email to reconfirm my
email address because the emails were meant to be bouncing....which is
strange because its my main email address and I have been getting emails
ok....anyway using gmail now.
So, here is my post again. Appologies if its already been
answered.
Hi All.
I am wondering if anyone has seen or has any Delphi code that
will do an http file upload, BUT that shows you the upload progress.
I have looked at the Synapse code for doing this, but it doesn't
have the ability to show the progress.
Why use HTTP File upload and not FTP? simple answer, not every
site has FTP enabled...as we have found out, and email has been a bit
unreliable.
I have taken a look at the odd Java plugin that does this which
would be good because I could just have my app. look at a webpage
instead of build it into the exe, but then, no guarantees that java is
enabled either....sigh...the joys :-(
OR someone might even have a brighter idea ;-)
Jeremy
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with
Subject: unsubscribe
--
---
Richard Vowles, Technical Advisor
Developers Inc Ltd
web. http://www.developers-inc.co.nz
ph. +64-9-3600231, mob. +64-275-467747, fax. +64-9-3600384
skype. rvowles, LinkedIn, Twitter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20080918/c59818bd/attachment-0001.html
More information about the Delphi
mailing list