Manuel Sarmiento

Member since: Wednesday, 03 January 2018
Last login: Never logged in.
Profile viewed: 572 views

No Rank
Points: 0

Manuel Sarmiento created a new topic ' AMAZON S3' in the forum. 5 years ago

I have a small command line application to upload/download/list items in S3 buckets
until X7 everything worked just fine
However, in 10.2, with exactly the same authentication, it works for upload/download but not for listing (getbucket)
TAmazonStorageService returns "Forbidden - The request signature we calculated does not match the signature you provided. Check your key and signing method. (SignatureDoesNotMatch)Date=Wed, 03 Jan 2018 19:55:38 GMT"
however the Key and the User are exsactly the same that are accepted when uploading/downloading
what is going on?
here is my code:
program AwsCL;
{$APPTYPE CONSOLE}
{$R *.res}
usesSystem.SysUtils,System.Classes,Data.Cloud.CloudAPI,Data.Cloud.AmazonAPI,utilities in '..\..\del_files\utilities.pas',ConfigUnit in '..\ALM\ConfigUnit.pas';
varAmazonConnectionInfo: TAmazonConnectionInfo;AmazonStorage : TAmazonStorageService;s : TFileStream;AmazonInfo : TCloudResponseInfo;Bucket,Path,LocalPath : Unicodestring;filename : Unicodestring;content : TBytes;AWSparam : Unicodestring;AWSParamList : TStringList;AWSResult : TAmazonBucketResult;i,totcount,rp : integer;firstname : Unicodestring;failed : boolean;
begintryAmazonInfo:=TCloudResponseInfo.Create;AmazonConnectionInfo:=TAmazonConnectionInfo.Create(nil);{ TODO -oUser -cConsole Main : Insert code here }AmazonConnectionInfo.AccountName:=ConfigParams.Values;AmazonConnectionInfo.AccountKey:=ConfigParams.Values;//AmazonConnectionInfo.Protocol:='HTTPS';writeln(AmazonConnectionInfo.AccountName,AmazonConnectionInfo.AccountKey);writeln(AmazonConnectionInfo.StorageEndpoint);writeln(AmazonConnectionInfo.UseDefaultEndpoints);writeln(AmazonConnectionInfo.RequestProxyHost);Bucket:=ConfigParams.Values;Path:=ConfigParams.Values;if path[length(path)]<>'/' then path:=path+'/';localPath:=ConfigParams.Values; if localpath[length(localpath)]<>'\' then localpath:=localpath+'\';filename:=replacedate(paramlist.values);if paramlist.Values<>'' thenbucket:=lowercase(paramlist.Values);if lowercase(paramlist.Values) ='upload' thenbegins:=TFileStream.Create(localpath+filename,fmOpenRead);setlength(content,s.Size);s.ReadBuffer(pointer(content)^,s.size);// for I := 0 to s.Size-1 do// write(content);
writeln('tamaƱo=',s.Size);amazonStorage:=TAmazonStorageService.Create(AmazonConnectionInfo);rp:=0;repeattryfailed:=false;AmazonStorage.UploadObject(bucket,path+filename,content,TRUE,nil,nil,amzbaPublicRead,AmazonInfo);exceptfailed:=true;end;inc(rp)until (rp=3) or ((amazonInfo.StatusCode=200) and not(failed));writeln('UPLOAD ',path+uppercase(filename),amazonInfo.StatusMessage,' ',amazonInfo.StatusCode, 'tries=',rp);s.Free;endelseif lowercase(paramlist.Values) ='download' thenbegins:=TFileStream.Create(localpath+filename,fmOpenWrite+fmCreate);amazonStorage:=TAmazonStorageService.Create(AmazonConnectionInfo);amazonStorage.GetObject(bucket,path+filename,s,amazonInfo);writeln('DOWNLOAD',amazonInfo.StatusMessage);s.free;endelseif lowercase(paramlist.Values) ='list' thenbeginAWSParamList:=TStringList.Create;Split(paramlist.Values,';',AWSParamList);// writeln(AWSParamList.Text);// s:=TFileStream.Create(localpath+filename,fmOpenWrite+fmCreate);AmazonConnectionInfo.StorageEndpoint:='s3.amazonaws.com';AmazonConnectionInfo.UseDefaultEndpoints:=false;writeln(AmazonConnectionInfo.StorageURL(bucket));amazonStorage:=TAmazonStorageService.Create(AmazonConnectionInfo);firstname:='';totcount:=0;repeatAWSParamList.Values:=firstname;//AWSParamList.Values:='/';AWSResult:=amazonStorage.GetBucket(bucket,AWSParamList,amazonInfo);writeln(amazoninfo.StatusMessage,amazoninfo.Headers.Text);// writeln(awsresult.name);if awsresult.Objects.Count>0 thenbeginfor I := 0 to awsresult.Objects.Count-1 dowriteln(awsresult.Objects.Name);firstname:=awsresult.Objects[AWSResult.Objects.count-1].name;end;until awsresult.Objects.Count=0;writeln('Total Files: ',totcount,' ',amazonInfo.StatusMessage);writeln(paramlist.Text);// for I := 0 to awsparamlist.count-1 do// writeln(awsparamlist);end;excepton E: Exception doWriteln(E.ClassName, ': ', E.Message);end;end.


Read More...