From 8de90cc2f81d959c4b45ce85e626fdfa6c373338 Mon Sep 17 00:00:00 2001 From: Exilon Date: Thu, 22 Oct 2020 09:43:42 +0200 Subject: [PATCH] [amazon] delphi 10.4 compatibility --- Quick.Amazon.pas | 87 +++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/Quick.Amazon.pas b/Quick.Amazon.pas index b8c4a46..b910627 100644 --- a/Quick.Amazon.pas +++ b/Quick.Amazon.pas @@ -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 @@ -29,6 +29,8 @@ unit Quick.Amazon; +{$i QuickLib.inc} + interface uses @@ -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; @@ -228,7 +232,6 @@ function TQuickAmazon.PutObject(amBucket, cFilename, amObjectName : string; amAC Content : TArray; CloudResponseInfo : TCloudResponseInfo; begin - Result := False; AmazonS3 := TAmazonStorage.Create(fconAmazon); if amBucket = '' then amBucket := '$root'; CloudResponseInfo := TCloudResponseInfo.Create; @@ -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; @@ -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'; @@ -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; @@ -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; @@ -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; @@ -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 := ''; @@ -437,7 +446,6 @@ function TQuickAmazon.ListObjectsNames(amBucket : string; amObjectsStartWith : s CloudResponseInfo : TCloudResponseInfo; cNextMarker : string; amParams : TStrings; - a : TAmazonBucketResult; begin Result := TStringList.Create; cNextMarker := ''; @@ -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; @@ -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; @@ -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; @@ -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.