Skip to content

Commit

Permalink
[amazon] delphi 10.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Oct 22, 2020
1 parent 37c616e commit 8de90cc
Showing 1 changed file with 53 additions and 34 deletions.
87 changes: 53 additions & 34 deletions Quick.Amazon.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Author : Kike Pérez
Version : 1.4
Created : 18/11/2016
Modified : 21/02/2018
Modified : 11/09/2020
This file is part of QuickLib: https://github.com/exilon/QuickLib
Expand All @@ -29,6 +29,8 @@

unit Quick.Amazon;

{$i QuickLib.inc}

interface

uses
Expand Down Expand Up @@ -111,7 +113,9 @@ TQuickAmazon = class
function ListBuckets(var amResponseInfo : TAmazonResponseInfo) : TStrings;
function CreateBucket(amBucket : string; amBucketRegion : TAmazonRegion; amACLType : TAmazonACLAccess; var amResponseInfo : TAmazonResponseInfo) : Boolean;
function DeleteBucket(amBucket : string; amBucketRegion : TAmazonRegion; var amResponseInfo : TAmazonResponseInfo) : Boolean;
{$IFNDEF DELPHISYDNEY_UP}
class function GetAWSRegion(Region: TAmazonRegion): string; overload;
{$ENDIF}
class function GetAWSRegion(const Region : string) : TAmazonRegion; overload;
end;

Expand Down Expand Up @@ -228,7 +232,6 @@ function TQuickAmazon.PutObject(amBucket, cFilename, amObjectName : string; amAC
Content : TArray<Byte>;
CloudResponseInfo : TCloudResponseInfo;
begin
Result := False;
AmazonS3 := TAmazonStorage.Create(fconAmazon);
if amBucket = '' then amBucket := '$root';
CloudResponseInfo := TCloudResponseInfo.Create;
Expand Down Expand Up @@ -258,13 +261,16 @@ function TQuickAmazon.PutObject(amBucket : string; cStream : TStream; amObjectNa
try
//AmazonS3.Timeout := fTimeout;
CloudResponseInfo := TCloudResponseInfo.Create;
//CloudResponseInfo.Headers.AddPair();
Content := StreamToArray(cStream);
Result := AmazonS3.UploadObject(amBucket,amObjectName,Content,False,nil,nil,amACLType,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
try
//CloudResponseInfo.Headers.AddPair();
Content := StreamToArray(cStream);
Result := AmazonS3.UploadObject(amBucket,amObjectName,Content,False,nil,nil,amACLType,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
SetLength(Content,0);
Content := nil;
end;
Expand All @@ -278,7 +284,7 @@ function TQuickAmazon.GetObject(amBucket, amObjectName, cFilenameTo : string; va
AmazonS3 : TAmazonStorage;
fs : TFileStream;
CloudResponseInfo : TCloudResponseInfo;
amParams : TAmazonGetObjectOptionals;
//amParams : TAmazonGetObjectOptionals;
begin
Result := False;
if amBucket = '' then amBucket := '$root';
Expand Down Expand Up @@ -309,7 +315,6 @@ function TQuickAmazon.GetObject(amBucket, amObjectName, cFilenameTo : string; va
function TQuickAmazon.GetObject(amBucket, amObjectName : string; var amResponseInfo : TAmazonResponseInfo) : TMemoryStream;
var
AmazonS3 : TAmazonStorage;
fs : TFileStream;
CloudResponseInfo : TCloudResponseInfo;
begin
Result := TMemoryStream.Create;
Expand All @@ -320,14 +325,17 @@ function TQuickAmazon.GetObject(amBucket, amObjectName : string; var amResponseI
//AmazonS3.Timeout := fTimeout;
CloudResponseInfo := TCloudResponseInfo.Create;
try
AmazonS3.GetObject(amBucket,amObjectName,Result,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
except
Result := nil;
try
AmazonS3.GetObject(amBucket,amObjectName,Result,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
except
Result := nil;
end;
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand Down Expand Up @@ -361,18 +369,20 @@ function TQuickAmazon.DeleteObject(amBucket,amObjectName : string; var amRespons
AmazonS3 : TAmazonStorage;
CloudResponseInfo : TCloudResponseInfo;
begin
Result := False;
if amBucket = '' then amBucket := '$root';
if amObjectName.StartsWith('/') then amObjectName := Copy(amObjectName,2,Length(amObjectName));
AmazonS3 := TAmazonStorage.Create(fconAmazon);
try
//AmazonS3.Timeout := fTimeout;
CloudResponseInfo := TCloudResponseInfo.Create;
Result := AmazonS3.DeleteObject(amBucket,amObjectName,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
try
Result := AmazonS3.DeleteObject(amBucket,amObjectName,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand All @@ -385,7 +395,6 @@ function TQuickAmazon.ListObjects(amBucket : string; amObjectsStartWith : string
CloudResponseInfo : TCloudResponseInfo;
cNextMarker : string;
amParams : TStrings;
a : TAmazonBucketResult;
begin
Result := TAmazonObjects.Create(True);
cNextMarker := '';
Expand Down Expand Up @@ -437,7 +446,6 @@ function TQuickAmazon.ListObjectsNames(amBucket : string; amObjectsStartWith : s
CloudResponseInfo : TCloudResponseInfo;
cNextMarker : string;
amParams : TStrings;
a : TAmazonBucketResult;
begin
Result := TStringList.Create;
cNextMarker := '';
Expand Down Expand Up @@ -510,20 +518,23 @@ function TQuickAmazon.ListBuckets(var amResponseInfo : TAmazonResponseInfo) : TS
try
//AmazonS3.Timeout := fTimeout;
CloudResponseInfo := TCloudResponseInfo.Create;
Buckets := AmazonS3.ListBuckets(CloudResponseInfo);
try
Result.Capacity := Buckets.Count;
for i := 0 to Buckets.Count -1 do
begin
Result.Add(Buckets.Names[i]);
Buckets := AmazonS3.ListBuckets(CloudResponseInfo);
try
Result.Capacity := Buckets.Count;
for i := 0 to Buckets.Count -1 do
begin
Result.Add(Buckets.Names[i]);
end;
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
Buckets.Free;
end;
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
Buckets.Free;
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand All @@ -538,11 +549,14 @@ function TQuickAmazon.CreateBucket(amBucket : string; amBucketRegion : TAmazonRe
AmazonS3 := TAmazonStorageService.Create(fconAmazon);
try
CloudResponseInfo := TCloudResponseInfo.Create;
Result := AmazonS3.CreateBucket(amBucket,amACLType,amBucketRegion,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
try
Result := AmazonS3.CreateBucket(amBucket,amACLType,amBucketRegion,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand All @@ -557,11 +571,14 @@ function TQuickAmazon.DeleteBucket(amBucket : string; amBucketRegion : TAmazonRe
AmazonS3 := TAmazonStorageService.Create(fconAmazon);
try
CloudResponseInfo := TCloudResponseInfo.Create;
Result := AmazonS3.DeleteBucket(amBucket,CloudResponseInfo,amBucketRegion);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
try
Result := AmazonS3.DeleteBucket(amBucket,CloudResponseInfo,amBucketRegion);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand All @@ -570,9 +587,11 @@ class function TQuickAmazon.GetAWSRegion(const Region : string) : TAmazonRegion;
Result := TAmazonStorageService.GetRegionFromString(Region);
end;

{$IFNDEF DELPHISYDNEY_UP}
class function TQuickAmazon.GetAWSRegion(Region: TAmazonRegion): string;
begin
Result := TAmazonStorageService.GetRegionString(Region);
end;
{$ENDIF}

end.

0 comments on commit 8de90cc

Please sign in to comment.