delphi通过url下载文件
Posted 坤霸天下
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了delphi通过url下载文件相关的知识,希望对你有一定的参考价值。
procedure TfrmEngineerImport.btnDownloadClick(Sender: TObject);
var
vsql, SourceFile, DestFile, filename, filepath: string;
DownLoadFile: TFileStream;
vUniqry: TUniQuery;
begin
vSql := ‘SELECT a.attachment_name,a.attachment_url FROM qo_order t inner join qo_order_schedule os on os.qo_order_id=t.id ‘ +
‘ inner join qo_order_sch_process p on p.qo_order_schedule_id=os.id ‘ +
‘ inner join qo_order_sch_process_atta a on a.qo_order_sch_process_id=p.id ‘ +
‘where t.wc_contract_id=413‘;
ServiceDataModule.GetUniQry(vUniqry);
ServiceDataModule.OpenUniQueryBySQL(vUniqry, vSql);
with vUniqry do
begin
First;
while not Eof do
begin
filepath := fieldbyname(‘attachment_url‘).AsString;
filename := fieldbyname(‘attachment_name‘).AsString;
SourceFile := ‘http://127.0.0.1:8080/‘ + filepath + ‘/‘ + filename;
DestFile := ‘c:\img\‘+filename;
{ if DownloadFile(AnsiToUtf8(SourceFile), DestFile) then
begin
mmoLog.Lines.Add(filename + ‘:Download succesful!‘)
end
else
begin
mmoLog.Lines.Add(SourceFile)
end; }
DownLoadFile := TFileStream.Create(DestFile, fmCreate);
IdHTTP1.Get(AnsiToUtf8(SourceFile), DownLoadFile);
DownLoadFile.Free;
Next;
end;
end;
ServiceDataModule.CloseUniQry(vUniqry);
end;
以上是关于delphi通过url下载文件的主要内容,如果未能解决你的问题,请参考以下文章
Delphi - 需要 XE2 代码到 Delphi7。使用wininet下载文件