Reference TS3Methods
Declared in Codebot.Networking.Storage.pas on line 181
TS3Methods is used to generate S3 REST requests. It builds HTTP request headers using an S3 compatible configuration providers. There are many S3 compatible services and they each have their own end point and regions. When you sign up with any S3 service they will provide you with access keys.
The headers generated by this class use the authorization version 4 signature scheme to verify you are the authorized user for their service account.
Reference:
https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html
Note:
You will need to either set valid access key environment variables for your preferred S3 compatible service or define your own TS3ConfigFactory where you can implement your own TS3KeyStore functions for retrieving access keys.
Bucket note:
Some requests require both a bucket and a region. If no region is given then the default region for the configured S3 service will be used. This may cause the request to be denied, so you might want to first retrieve and then cache the bucket region using the GetBucketLocation request.
Example usage:
S3 := TS3Methods.Create(S3Config.Wasabi); ... Request := S3.ListBuckets; if S3.Send(Request, Document) then
WriteLn(Document.Text);
WriteLn(Document.Text);
TS3Methods = class
public
{ Create S3 methods using a named provider configuration }
constructor Create(const AProvider: string);
destructor Destroy; override;
{ Reconfigure replaces the current config and erases bucket region memory }
procedure Reconfigure(const AProvider: string);
{ Find a bucket's region directly and cache it in memory. If a bucket region
is unknown this method will block while a query is dispatched. }
function FindRegion(const Bucket: string): string;
{ Add a bucket's region to the memory cache manually }
procedure AddRegion(const Bucket, Region: string);
{ Request to list all buckets }
function ListBuckets: TS3Request;
{ Request to get bucket region. Due to legacy constraints a blank value
returned from this request should be interpreted as us-east-1. }
function GetBucketLocation(const Bucket: string): TS3Request;
{ Request to get bucket access control list }
function GetBucketAcl(const Bucket: string): TS3Request;
{ Request to get bucket CORS }
function GetBucketCors(const Bucket: string): TS3Request;
{ Request to get bucket policy }
function GetBucketPolicy(const Bucket: string): TS3Request;
{ Request to get bucket request payment }
function GetBucketRequestPayment(const Bucket: string): TS3Request;
{ Request to get bucket tagging }
function GetBucketTagging(const Bucket: string): TS3Request;
{ Request to get bucket versioning }
function GetBucketVersioning(const Bucket: string): TS3Request;
{ Request to get bucket website }
function GetBucketWebsite(const Bucket: string): TS3Request;
{ Request to list bucket objects }
function ListObjects(const Bucket: string; NextToken: string = ''; Prefix: string = ''; Delimiter: string = ''): TS3Request;
{ Generate a presigned url for public access to an object }
function Presign(const Bucket, Path: string; Expires: Integer = 0): string;
{ Send a request to your S3 servers outputting the response to a XML
document. Returns true if the status code is 200 OK.
First overload can be used when querying or sending commands to S3 Second
overload can be used when receiving files from S3 }
function Send(const Request: TS3Request; out Response: IDocument): Boolean; overload;
function Send(const Request: TS3Request; Stream: TStream): Boolean; overload;
{ SendAsync is identical to the method Send above but performed
asynchronously.
When sending an async request the task status will be success if the
response status is 200 OK. The completion notification will receive either
a response document or a stream as the result argument.
Failure to provide a completion notification will cause the response
document or stream to be discarded. When using the stream variant you
might want to free the stream upon completion.
Example usage:
procedure ListingComplete(Task: IAsyncTask; Result: IDocument); begin
if Task.Status = asyncSuccess then
WriteLn(Result.Xml);
end;
Request := S3.ListObjects(Bucket); Task := NewDocTask(ListingComplete);
S3.SendAsync(Request, Task); }
procedure SendAsync(const Request: TS3Request; Task: IAsyncDocTask); overload;
procedure SendAsync(const Request: TS3Request; Stream: TStream; Task: IAsyncStreamTask); overload;
{ The current provider configuration }
property Config: TS3Config read GetConfig;
end;See also
IDocument in Codebot.Text.Xml.pas