S3 compatible API for UnityBase

  
      const s3Client = new aws.S3Client({
  URL: 'http://localhost:9000',
  credentials: {
    accessKeyId: '....',
    secretAccessKey: '...'
  }
})
s3Client.listBuckets() //  [{"Name":"ubbs","CreationDate":"2024-01-03T09:11:57.815Z"},{"Name":"ubbs-ver","CreationDate":"2024-04-25T12:43:39.789Z"}]
// upload buffer to bucket. Content type will be calculated based on `bucketKey` extension
s3Client.upload({
  bucket: 'ubbs',
  bucketKey: '2024/01/01/test.txt',
  buffer: Buffer.from('Hello, світ!')
})
  

# new S3Client (opt:  object)

Arguments:
  • opt: object
    • URL:  string

      S3 URL. Example: AWS - https://s3.us-east-1.amazonaws.com, local min.io - http://localhost:9000

    • region='us-east-1':  string

      AWS region

    • credentials:  object

      Credentials

Methods

# checkRespError (resp:  IncomingMessage) instance

Check response is valid or throw

Arguments:

# computeAwsHttpRequestParams (options:  object) → Object instance

Sign an AWS request. See https://docs.aws.amazon.com/IAM/latest/UserGuide/create-signed-request.html

Arguments:

# delete (params:  object) → boolean instance

Delete object from s3 from either s3url or bucket+bucketKey or throw. See https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObject.html

Arguments:
  • params: object
    • s3url:  string

      Url in format s3://bucket/bucketKey. If passed - preferred over params.bucket and params.bucketKey

    • bucket:  string

      Bucket to delete from

    • bucketKey:  string

      A key to delete, for example 2024/01/01/12211221.pdf

    • additionalHeaders:  object

# download (params:  object) → string | UBMail.TubSendMailAttachKind.Buffer | ArrayBuffer instance

Download object from s3 from either s3url or bucket+bucketKey. See https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html

Arguments:
  • params: object
    • s3url:  string

      Url in format s3://bucket/bucketKey. If passed - preferred over params.bucket and params.bucketKey

    • bucket:  string

      Bucket to put data

    • bucketKey:  string

      A key to put data into, for example 2024/01/01/12211221.pdf

    • additionalHeaders:  object

    • encoding='bin':  object

# list (params:  object) instance

List bucket content. See https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html

Arguments:
  • params: object
    • bucket:  string

      Bucket to list

    • pathInBucket='/':  string

      path in bucket (ends with /) or '/' for root

# listAll (params:  object) → Array instance

List of all items in the bucket. See https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjects.html https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html

Arguments:
  • params: object
    • bucket:  string

      Bucket to list

    • maxKeys:  number

      Number of items

    • pathInBucket='/':  string

      path in bucket (ends with /) or '/' for root

    • v2:  boolean

      use ListObjectsV2 instead ListObjects

# listBuckets (paramsopt:  object) → Array.<{Name: string, CreationDate: string}> instance

List buckets. https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBuckets.html

Arguments:

# upload (params:  object) → boolean instance

Put data into specified s3url or bucket+bucketKey. Either binary data in params.buffer or path to file in params.filePath must be specified

If additionalHeaders['content-type'] is not specified will take a content-type from a bucketKey extension.

Will throw on error or return true on success

Arguments:
  • params: object
    • s3url:  string

      Url in format s3://bucket/bucketKey. If passed - preferred over params.bucket and params.bucketKey

    • bucket:  string

      Bucket to put data

    • bucketKey:  string

      A key to put data into, for example 2024/01/01/12211221.pdf

    • filePath:  string

      Path to file to put into bucket

    • buffer:  ArrayBufferLike

      A binary data to put (if filePath is not specified)

    • urlParams:  object

      A URL params for request - keys are param name

    • additionalHeaders:  object