O
onyliu
Unregistered / Unconfirmed
GUEST, unregistred user!
上传到数据库 blob字段 下载从数据库 blob字段 用TFileStream保存由于文件在10M左右 上传、更新的时候都会出现 未响应下载------------------------- try if Count = 0 then begin BlobStream.Position := 0; Count := BlobStream.Size; end; if Count > MaxBufSize then BufSize := MaxBufSize else BufSize := Count; GetMem(Buffer, BufSize); vProgressBar.Position := 0; vProgressBar.Max := count div bufsize;//每次写入文件的数据流大小为bufsize,所以max为count 除以 bufsize try while Count <> 0 do begin if Count > BufSize then N := BufSize else N := Count; BlobStream.ReadBuffer(Buffer^, N);//从数据库表中取数据流 FileStream.WriteBuffer(Buffer^, N);//将数据流写入文件 Dec(Count, N); vLable.Caption := '下载文件进度 :'+ IntToStr(vProgressBar.Position) + '%' + ' 可能需要几分钟,请稍等...'; vProgressBar.Position := vProgressBar.Position + 1; Application.ProcessMessages; end; finally FreeMem(Buffer, BufSize); end; finally BlobStream.Free; end; 上传---------------------------- try Stream := vQuery.CreateBlobStream(vQuery.FieldByName(FieldBlobName), bmWrite); GetMem(Buffer, BufSize); try vLabel.Caption := '准备读取文件...'; Count := FileStream.Size; vProgressBar.Position := 0; while Count <> 0 do begin if Count > BufSize then N := BufSize else N := Count; FileStream.ReadBuffer(Buffer^, N); Stream.WriteBuffer(Buffer^, N); Dec(Count, N); vLabel.Caption := '读取文件进度: '+ IntToStr(vProgressBar.Position) +' %'; vProgressBar.Position := vProgressBar.Position + 1; end; finally FreeMem(Buffer, BufSize); Stream.Free; end; Application.ProcessMessages; vLabel.Caption := '读取文件成功,正在上传文件,可能需要几分钟,请稍等...'; Application.ProcessMessages; vQuery.applyupdates; vQuery.commitupdates; finally vProgressBar.Position := vProgressBar.Max; FileStream.Free; vQuery.Close; end;