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)
Methods
# checkRespError (resp: IncomingMessage) instance
Check response is valid or throw
Arguments:
resp
: IncomingMessage
# computeAwsHttpRequestParams (options: object) → Object instance
Sign an AWS request. See https://docs.aws.amazon.com/IAM/latest/UserGuide/create-signed-request.html
# 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
# 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
# head (params: object) → boolean | object instance
Retrieve object metadata. Returns false
if object does not exist
# list (params: object) instance
List bucket content. See https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html
# listBuckets (paramsopt: object) → Array.<{Name: string, CreationDate: string}> instance
List buckets. https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListBuckets.html
# 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
: objects3url
: stringUrl in format
s3://bucket/bucketKey
. If passed - preferred overparams.bucket
andparams.bucketKey
bucket
: stringBucket to put data
bucketKey
: stringA key to put data into, for example
2024/01/01/12211221.pdf
filePath
: stringPath to file to put into bucket
buffer
: ArrayBufferLikeA binary data to put (if filePath is not specified)
urlParams
: objectA URL params for request - keys are param name
additionalHeaders
: object