Download Now
Forums

    Reference TS3Methods

    Declared in Codebot.Networking.Storage.pas on line 215

    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 set Config.AccessId and Config.SecretKey directly.
    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('wasabi'); ... Request := S3.ListBuckets; if S3.Send(Request, Document) then
    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. Pass the result to Config.LocationRegion to
          convert it to a region. }
        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;
        { Request to download an object. Send the request with Send or SendAsync
          along with a stream to receive the object's contents. }
        function GetObject(const Bucket, Key: string): TS3Request;
        { Request an object's details without its contents. The response has no
          body, so read the details with S3ResponseHeader, for example
          Content-Length, Content-Type, Last-Modified, ETag, x-amz-storage-class,
          and user metadata named x-amz-meta-*. }
        function HeadObject(const Bucket, Key: string): TS3Request;
        { Request to upload an object of a given size. Send the request with
          SendObject or SendObjectAsync along with a stream of the object's
          contents. The access argument can upload the object as private or public.
          See TS3Access for which providers accept this. }
        function PutObject(const Bucket, Key: string; Size: Int64; const ContentType: string = ''; Access: TS3Access = accessDefault): TS3Request;
        { Request to delete an object }
        function DeleteObject(const Bucket, Key: string): TS3Request;
        { Request to get an object access control list }
        function GetObjectAcl(const Bucket, Key: string): TS3Request;
        { Request to make an existing object private or public. The value
          accessDefault is treated as accessPrivate. }
        function PutObjectAcl(const Bucket, Key: string; Access: TS3Access): 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 a 2xx success code.
    
          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;
        { SendObject sends a PutObject request followed by the object contents read
          from body. The body is read from its current position and is not freed.
          SendObjectAsync is the same but performed asynchronously, and the body
          must remain valid until the task completes. }
        function SendObject(const Request: TS3Request; Body: TStream; out Response: IDocument): Boolean;
        procedure SendObjectAsync(const Request: TS3Request; Body: TStream; Task: IAsyncDocTask);
        { The current provider configuration }
        property Config: TS3Config read GetConfig;
      end;

    See also

    IDocument in Codebot.Text.Xml.pas