我使用Data.Cloud.AmazonAPI中的DataObject将一些文件上传到AWS S3,它可以工作,但是我如何在上传或下载时获得进度信息?这是我的代码:
function ByteContent(DataStream: TStream): TBytes;
var
Buffer: TBytes;
begin
if not Assigned(DataStream) then
exit(nil);
SetLength(Buffer, DataStream.Size);
DataStream.Position := 0;
if DataStream.Size > 0 then
DataStream.Read(Buffer[0], DataStream.Size);
Result := Buffer;
end;
function TForm1.UploadFile(LocalFilePath: string; RemoteFileName: string; Bucket: string): Boolean;
var
Service: TAmazonStorageService;
ConAmazon: TAmazonConnectionInfo;
FS: TFileStream;
Content: TBytes;
begin
try
ConAmazon := TAmazonConnectionInfo.Create(nil);
ConAmazon.AccountKey := 'MtJqIM7WyjJA*********************';
ConAmazon.AccountName := 'AKIAIXVAH*********';
ConAmazon.QueueEndpoint := 'queue.amazonaws.com';
ConAmazon.StorageEndpoint := 's3-eu-west-1.amazonaws.com';
ConAmazon.TableEndpoint := 'sdb.amazonaws.com';
ConAmazon.UseDefaultEndpoints := True;
Service := TAmazonStorageService.Create(ConAmazon);
if FileExists(LocalFilePath) then
begin
FS := TFileStream.Create(LocalFilePath, fmOpenRead);
Content := ByteContent(FS);
FS.Free;
Result := Service.UploadObject(Bucket, RemoteFileName, Content, True, nil, nil, amzbaPrivate, nil, OnProgress);
end
else
Result := False;
finally
ConAmazon.Free;
Service.Free;
end;
end;
1条答案
按热度按时间9udxz4iz1#
Can I monitor the progress of an S3 download using the Cloud.AmazonAPI?上传的方法与此类似,但你需要创建
TAmazonStorageService
子类,如下所示progress函数如下所示
TProgressStream
像这样