Para fazer o download de arquivos, inclusive imagens, via web, uso uma função genérica, mostrada a seguir (Delphi6):
Function Download1URL(const a1Url, a1Dst: string): Boolean;
Begin
bStatFc1 := False;
If bIsConDirect then
hSession1 := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0)
Else
hSession1 := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
{EndIf}
Try
If Assigned(hSession1) then
Begin
hService1 := InternetOpenUrl(hSession1, PChar(a1Url), nil, 0, 0, 0);
If Assigned(hService1) then
Begin
Try
AssignFile(ftSaveFile1, a1Dst);
ReWrite(ftSaveFile1, 1);
bOpen2Save1 := True;
While True do Begin
dwBytesRead1 := iMemLimit;
InternetReadFile(hService1, @lpBuffer1, iMemLimit, dwBytesRead1);
iBytesRec1 := iBytesRec1+dwBytesRead1;
If dwBytesRead1=0 then break;
lpBuffer1[dwBytesRead1] := 0;
BlockWrite(ftSaveFile1, lpBuffer1, dwBytesRead1);
End;{While True}
bStatFc1 := iBytesRec1>0;
Finally
InternetCloseHandle(hService1);
If bOpen2Save1 then
CloseFile(ftSaveFile1);
{EndIf}
End;
End;
{EndIf Assigned(hService)}
End;
{EndIf Assigned(hSession)}
Finally
InternetCloseHandle(hSession1);
End;
Download1URL := bStatFc1;
End;
{Observação: algumas variáveis, como iMemLimit, estão definidas em outros pontos do programa... iMemLimit, p.e., é inicializada com 16384...
}
Pergunta
paulobergo
Bom dia...
Para fazer o download de arquivos, inclusive imagens, via web, uso uma função genérica, mostrada a seguir (Delphi6):
Function Download1URL(const a1Url, a1Dst: string): Boolean; Begin bStatFc1 := False; If bIsConDirect then hSession1 := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0) Else hSession1 := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); {EndIf} Try If Assigned(hSession1) then Begin hService1 := InternetOpenUrl(hSession1, PChar(a1Url), nil, 0, 0, 0); If Assigned(hService1) then Begin Try AssignFile(ftSaveFile1, a1Dst); ReWrite(ftSaveFile1, 1); bOpen2Save1 := True; While True do Begin dwBytesRead1 := iMemLimit; InternetReadFile(hService1, @lpBuffer1, iMemLimit, dwBytesRead1); iBytesRec1 := iBytesRec1+dwBytesRead1; If dwBytesRead1=0 then break; lpBuffer1[dwBytesRead1] := 0; BlockWrite(ftSaveFile1, lpBuffer1, dwBytesRead1); End;{While True} bStatFc1 := iBytesRec1>0; Finally InternetCloseHandle(hService1); If bOpen2Save1 then CloseFile(ftSaveFile1); {EndIf} End; End; {EndIf Assigned(hService)} End; {EndIf Assigned(hSession)} Finally InternetCloseHandle(hSession1); End; Download1URL := bStatFc1; End; {Observação: algumas variáveis, como iMemLimit, estão definidas em outros pontos do programa... iMemLimit, p.e., é inicializada com 16384... }Exemplo:
Download1URL('http://200.251.137.2/logoprin.jpg', 'c:\temp\logoprin.jpg');
Bom... o que eu gostaria de saber é se existe alguma outra forma de baixar uma arquivo que seja
mais rápida do que a "InternetReadFile" acima...
Grato por quaisquer dicas!!!!
Abraços!
Link para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.