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 (optobject)

Arguments:
  • opt: object
    • URLstring

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

    • region='us-east-1'string

      AWS region

    • credentialsobject

      Credentials

Methods

# checkRespError (respIncomingMessage) instance

Check response is valid or throw

Arguments:

# computeAwsHttpRequestParams (optionsobject) → Object instance

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

Arguments:

# delete (paramsobject) → 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
    • s3urlstring

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

    • bucketstring

      Bucket to delete from

    • bucketKeystring

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

    • additionalHeadersobject

# download (paramsobject) → 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
    • s3urlstring

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

    • bucketstring

      Bucket to put data

    • bucketKeystring

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

    • additionalHeadersobject

    • encoding='bin'object

# list (paramsobject) instance

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

Arguments:
  • params: object
    • bucketstring

      Bucket to list

    • pathInBucket='/'string

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

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

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

Arguments:

# upload (paramsobject) → 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
    • s3urlstring

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

    • bucketstring

      Bucket to put data

    • bucketKeystring

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

    • filePathstring

      Path to file to put into bucket

    • bufferArrayBufferLike

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

    • urlParamsobject

      A URL params for request - keys are param name

    • additionalHeadersobject