landgraf-dev / aws-sdk-delphi

AWS (Amazon Web Services) SDK for Delphi.
Other
125 stars 31 forks source link

Exception ES3InvalidArgument with message 'The continuation token provided is incorrect' #7

Closed joydeep-das5 closed 8 months ago

joydeep-das5 commented 8 months ago

Hi,

I am trying to get a list of folders from a s3 bucket. The bucket contains more than 2K folders. When I am trying to use "NextContinuationToken", it gives the above error. Can you please help?

PS: I have tried the code from https://github.com/appercept/aws-sdk-delphi-samples/tree/main/S3Explorer and that also gives me the same error.

Thanks

wlandgraf commented 8 months ago

Can you please provide the exact code you are using?

joydeep-das5 commented 8 months ago

Hi, I have created the following console application and tried to reproduce the error by specifying "MaxKeys" = 2. I don't actually need thousands of items in the bucket. The issue can be reproduced if there are more than 2 items in the bucket. Hope this will help to fix the issue.

`program S3Viewer;

{$APPTYPE CONSOLE}

{$R *.res}

uses System.SysUtils, Classes, AWS.S3;

function GetFirstBucket: IS3Bucket; var S3Client: IS3Client; i : Integer; begin S3Client := TS3Client.Create();

var Response := S3Client.ListBuckets;

for var Bucket in Response.Buckets do begin Result := Bucket; Break; end; end;

var v2Request : IS3ListObjectsV2Request; v2Response : IS3ListObjectsV2Response; S3Client: IS3Client; I : Integer; S3Bucket : IS3Bucket; Options : IS3Options; BucketName, s : String; begin Options := TS3Options.Create; try S3Bucket := GetFirstBucket;

Options.Region := S3Bucket.Location;
S3Client := TS3Client.Create( Options);

v2Request := TS3ListObjectsV2Request.Create( S3Bucket.Name);
v2Request.Bucket := S3Bucket.Name;
v2Request.MaxKeys := 2;

repeat
  v2Response := S3Client.ListObjectsV2( v2Request);
  for var Content in v2Response.Contents do
  begin
    Writeln( Content.Key);
  end;

  v2Request.ContinuationToken := v2Response.NextContinuationToken;
until ( not v2Response.IsTruncated);
Readln( s);

except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. `

The fils is also attached herewith. S3 Viewer.zip

image

Thanks !

wlandgraf commented 8 months ago

That code is from another AWS SDK for Delphi. Note that our SDK doesn't have official support for S3 yet, although it's implemented and should be officially released in a couple of weeks. To use S3 with our SDK, you currently have to use the s3 branch from the repository. It should work fine.

If you run into any issue, please provide the exact code you are using. so we can trace and reproduce the issue.

joydeep-das5 commented 8 months ago

Sorry ! my bad.. Will give it a try with your SDK. Thanks !