我的做法:将文件分解成字符串存入数据库(当时是FREESBD+MYSQL) //将文件分解读入LST with flStream do begin iSumReadCount := 0; while iSumReadCount < size do begin iReadSize := size - iSumReadCount; // 需要读入字节 = 文件大小 - 已读字节 if iReadSize > FIniInf.MaxFileSize then //如果需要读入字节大于缓冲长度 iReadSize := FIniInf.MaxFileSize; //则读入缓冲长度数量的字节 s := ''; setlength(s, iReadSize); Read(pointer(@s[1])^, iReadSize); //将读入的字节保存到LST lst.Add(s); iSumReadCount := iSumReadCount + iReadSize; //已读字节 Application.ProcessMessages; end; end; //遍历LST将字符串写入数据库 //下载过程
//下载字符串 while not eof do begin s := s + FieldByName('ZCONTENT').AsString; Next; Application.ProcessMessages; end;
//将字符串保存为文件 if s <> '' then try FileHandle := FileCreate(sFileName); FileWrite(FileHandle, s[1], length(s)); FileClose(FileHandle); WriteMm(format('下载成功:%s。',[sFileName])); except on e:exception do begin WriteMm(format('%s下载失败;Error:%s。', [sFileName, e.Message])); end; end;
2,用indy的组件
//将文件分解读入LST
with flStream do
begin
iSumReadCount := 0;
while iSumReadCount < size do
begin
iReadSize := size - iSumReadCount; // 需要读入字节 = 文件大小 - 已读字节
if iReadSize > FIniInf.MaxFileSize then //如果需要读入字节大于缓冲长度
iReadSize := FIniInf.MaxFileSize; //则读入缓冲长度数量的字节
s := '';
setlength(s, iReadSize);
Read(pointer(@s[1])^, iReadSize); //将读入的字节保存到LST
lst.Add(s);
iSumReadCount := iSumReadCount + iReadSize; //已读字节
Application.ProcessMessages;
end;
end;
//遍历LST将字符串写入数据库
//下载过程
//下载字符串
while not eof do
begin
s := s + FieldByName('ZCONTENT').AsString;
Next;
Application.ProcessMessages;
end;
//将字符串保存为文件
if s <> '' then
try
FileHandle := FileCreate(sFileName);
FileWrite(FileHandle, s[1], length(s));
FileClose(FileHandle);
WriteMm(format('下载成功:%s。',[sFileName]));
except
on e:exception do
begin
WriteMm(format('%s下载失败;Error:%s。', [sFileName, e.Message]));
end;
end;