A wrapper class that uses native delphi integration to amazon storage service.
[Optional]
For ease I recommend using the Boss for installation
- Boss - Dependency Manager for Delphi
boss install github.com/mateusvicente100/amazon-storage-service
Add the following folder to your project, in Project > Options > Resource Compiler > Directories and Conditionals > Include file search path
../amazon-storage-service/src
You need to use Amazon.Storage.Service
uses Amazon.Storage.Service;
First of all you need at once configure the amazon settings to connect in the server. This sould be done on start of your program.
procedure InitializeAmazonService;
begin
TAmazonStorageServiceConfig.GetInstance.AccessKey := 'your-access-key';
TAmazonStorageServiceConfig.GetInstance.SecretKey := 'your-secret-key';
TAmazonStorageServiceConfig.GetInstance.Region := TAmazonRegion.YourRegion;
TAmazonStorageServiceConfig.GetInstance.Protocol := TAmazonProtocol.http;
TAmazonStorageServiceConfig.GetInstance.MainBucketName := 'your-main-bucket-name'; // Optional
end;
You can list all your buckets
procedure ListAllBuckets;
var
LBuckets: TStrings;
I: Integer;
begin
LBuckets := TAmazonStorageService.New.ListBuckets;
try
for I := 0 to Pred(LBuckets.Count) do
memoLog.Lines.Add(LBuckets.Names[I]);
finally
LBuckets.Free;
end;
end;
You can create a bucket sending the bucket name
procedure CreateBucket(const ABucketName: string);
begin
TAmazonStorageService.New.CreateBucket(ABucketName);
end;
You can delete a bucket sending the bucket name
procedure CreateBucket(const ABucketName: string);
begin
TAmazonStorageService.New.DeleteBucket(ABucketName);
end;
You can list all files from one specific bucket
procedure ListAllFilesFromBucket(const ABucketName: string);
var
LFiles: TAmazonBucketResult;
LFile: TAmazonObjectResult;
begin
LFiles := TAmazonStorageService.New.GetBucket(ABucketName);
try
for LFile in LFiles.Objects do
memoLog.Lines.Add(LFile.Name);
finally
LFiles.Free;
end;
end;
You can upload a file using the file directory and main bucket name or using a specific bucket name
procedure UploadFile(const AFileDirectory: string);
begin
TAmazonStorageService.New.UploadFile(AFileDirectory);
end;
You can delete a file using the file name and main bucket name or using a specific bucket name
procedure DeleteFile(const AFileName: string);
begin
TAmazonStorageService.New.DeleteFile(AFileName);
end;
You can download a file using the file name with the bucket main name or using a specific bucket name
procedure DownloadFile(const AFileName: string);
begin
TAmazonStorageService.New.DownloadFile(AFileName);
end;