作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
TAmazonStorageService
中有可用的例程吗?监视对象下载的进度?
我读到可以使用 AWS SDK Hook WriteObjectProgressEvent
,但我在 Embarcadero's AmazonAPI 的文档中找不到任何相关内容.
最佳答案
我认为 Delphi 目前还没有实现这一点。您可以做的是创建一个流包装器,它将通知写入它的进度。例如,您可以编写以下内容来通过 ProgressBar 监视进度
procedure TForm1.OnProgress(const ACount: Int64);
begin
ProgressBar1.Value := ProgressBar1.Value + ACount;
Application.ProcessMessages;
end;
procedure TForm1.DownloadFile(const ABucketName: string; const AFileName: TFileName);
var
ResponseInfo: TCloudResponseInfo;
StorageService: TAmazonStorageService;
ObjectName: string;
FileStream: TStream;
ProgressStream: TProgressStream;
MetaData: TStrings;
Properties: TStrings;
ContentLength: Int64;
begin
StorageService := TAmazonStorageService.Create(AmazonConnectionInfo1);
ResponseInfo := TCloudResponseInfo.Create;
try
ObjectName := ExtractFileName(AFileName);
if StorageService.GetObjectProperties(ABucketName, ObjectName, Properties, MetaData) then
begin
try
ContentLength := StrToInt(Properties.Values['Content-Length']);
finally
MetaData.Free;
Properties.Free;
end;
FileStream := TFileStream.Create(AFileName, fmCreate or fmOpenWrite);
ProgressStream := TProgressStream.Create(FileStream);
ProgressStream.OnProgress := OnProgress;
ProgressBar1.Max := ContentLength;
ProgressBar1.Value := 0;
try
StorageService.GetObject(CBucketName, ObjectName, ProgressStream);
finally
ProgressStream.Free;
FileStream.Free;
end;
end;
finally
StorageService.Free;
ResponseInfo.Free;
end;
end;
和TProgressStream
实现如下
type
TOnProgressEvent = procedure(const ACount: Int64) of object;
TProgressStream = class(TStream)
strict private
FStream: TStream;
protected
function GetSize: Int64; override;
procedure SetSize(NewSize: Longint); overload; override;
procedure SetSize(const NewSize: Int64); overload; override;
public
OnProgress: TOnProgressEvent;
function Read(var Buffer; Count: Longint): Longint; overload; override;
function Write(const Buffer; Count: Longint): Longint; overload; override;
function Read(Buffer: TBytes; Offset, Count: Longint): Longint; overload; override;
function Write(const Buffer: TBytes; Offset, Count: Longint): Longint; overload; override;
function Seek(Offset: Longint; Origin: Word): Longint; overload; override;
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; overload; override;
constructor Create(const AStream: TStream);
end;
constructor TProgressStream.Create(const AStream: TStream);
begin
FStream := AStream;
end;
function TProgressStream.GetSize: Int64;
begin
Result := FStream.Size;
end;
procedure TProgressStream.SetSize(NewSize: Longint);
begin
FStream.Size := NewSize;
end;
procedure TProgressStream.SetSize(const NewSize: Int64);
begin
FStream.Size := NewSize;
end;
function TProgressStream.Read(var Buffer; Count: Longint): Longint;
begin
Result := FStream.Read(Buffer, Count);
end;
function TProgressStream.Write(const Buffer; Count: Longint): Longint;
begin
Result := FStream.Write(Buffer, Count);
end;
function TProgressStream.Read(Buffer: TBytes; Offset, Count: Longint): Longint;
begin
Result := FStream.Read(Buffer, Offset, Count);
end;
function TProgressStream.Write(const Buffer: TBytes; Offset, Count: Longint): Longint;
begin
Result := FStream.Write(Buffer, Offset, Count);
if Assigned(OnProgress) then
begin
OnProgress(Count);
end;
end;
function TProgressStream.Seek(Offset: Longint; Origin: Word): Longint;
begin
Result := FStream.Seek(Offset, Origin);
end;
function TProgressStream.Seek(const Offset: Int64; Origin: TSeekOrigin): Int64;
begin
Result := FStream.Seek(Offset, Origin);
end;
关于delphi - 我可以使用 Cloud.AmazonAPI 监控 S3 下载的进度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41899949/
使用 AmazonApi for python 时,出现错误 503。这真的很奇怪,因为相同的脚本直到三天前才起作用。从那时起,它给出了错误 503。我做了一些研究,发现当一秒钟提交太多请求时,亚马逊
TAmazonStorageService中有可用的例程吗?监视对象下载的进度? 我读到可以使用 AWS SDK Hook WriteObjectProgressEvent ,但我在 Embarcad
我是一名优秀的程序员,十分优秀!