我有一个时间关键的过程,将 JPG 图像(大约 10 张照片,每张大约 150KB)发送到 Web 服务器。在发送时,我想让用户执行其他操作,例如输入或选择其他数据,以加快整个过程。
我已经尝试过线程,但没有经验,所以我的第一次尝试是最好的情况 - 一样。否则,德尔福挂断等...
_____________________________________________________________________
procedure DoOnCameraGrabFoto(iID:integer; pic: TPicture; iTyp: Byte; ts: TDateTime);
const
SVC_AddFoto2Master='';
var
req: TIdMultiPartFormDataStream;
blob: TStream;
begin
with dtsBlobs.DataSet do begin
// At first add images to local dataset, just to see them...
Append;
FieldByName('MasterID').Value:=iID;
FieldByName('DateAndTime').Value := ts;
FieldByName('PhotoType').Value := iTip;
blob:=CreateBlobStream((FieldByName('FotoObj') as TBlobField), bmWrite);
try
pic.Graphic.SaveToStream(blob);
////////////////////////////////////////////////////
//
// POST foto to server with Indy (Delphi 7)
//
req:=TIdMultiPartFormDataStream.Create;
try
req.AddFormField('iMasterID', IntToStr(iID));
req.AddFormField('iTyp' , IntToStr(iTip));
req.AddFormField('tsPhoto' , DateToSqlDate(ts, false)+ ' ' + TimeToStr(ts));
req.AddObject('oFoto', 'image/jpeg', blob, 'photo' );
// Folowing method do something like shown below
// ExecPostRequest('http://server:80/svcWebServiceThatPostData', req);
//
// ... and there is no problem when there are only one foto or two.
// But, when there is lot a fotos, in this meantime, operator can for example
// fill-out the form, or something else.
//
//
IdHTTP1.Request.ContentType:=req.RequestContentType;
result:=IdHTTP1.Post(sUrl, req);
finally
req.Free;
end;
//
///////////////////////////////////////////////////////
finally
blob.Free;
end;
Post;
end;