Skip to content

Service

constructor (options)

Create an instance of the service with the given options:

ParameterDescriptionRequired
s3Clientthe s3Client configuration.yes
bucketthe bucket to use.yes
prefixan optional prefix to use when computing the final Keyno
btoathe binary to ascii function used to transform sent data into a string. Default is to transform to base64.no
atobthe ascii to binary function used to transform received data into a Buffer. Default is to transform back from base64.no

find (params)

Lists some objects in a bucket according given criteria provided in the params.query object.

Check the ListObjectsCommandInput documentation to have the list of supported poperties.

create (data, params)

Generates a presigned URL for the following commands:

The payload data must contain the following properties:

PropertyDescription
commandthe command for which the presigned URL should be created. The possible values are GetObject, PutObject and UploadPart.
idthe object key. Note that the final computed Key takes into account the prefix option of the service.
UploadIdthe UploadId generated when calling the createMultipartUpload method. It is required if the command is UploadPart
PartNumberthe PartNumber of the part to be uploaded. It is required if the command is UploadPart

get (id, params)

Get an object content from a bucket.

ParameterDescription
idthe object key. Note that the final computed Key takes into account the prefix option of the service.

NOTE

The object will be entirely read and transferred to the client, for large files consider using presigned URLs instead.

remove (id, params)

Remove an object from the bucket.

ParameterDescription
idthe object key. Note that the final computed Key takes into account the prefix option of the service.

The params.query object supports the following property:

Query parameterDescription
recursivewhen true, treats id as a prefix and removes all objects whose key starts with it. Internally paginates through ListObjectsCommand and batch-deletes via DeleteObjectsCommand.

When recursive is true the response shape is { id, deleted } where deleted is an array of the objects that were removed. Otherwise the standard DeleteObjectCommandOutput is returned.

createMultipartUpload (data, params)

Initiate a multipart upload.

It wraps the CreateMultipartUploadCommand.

The payload data must contain the following properties:

PropertyDescription
idthe object key. Note that the final computed Key takes into account the prefix option of the service.
typethe content type to be uploaded.

Any optional properties are forwarded to the underlying CreateMultipartUploadCommand command parameters.

completeMultipartUpload (data, params)

Finalize a multipart upload.

It wraps the CompleteMultipartUploadCommand.

The payload data must contain the following properties:

PropertyDescription
idthe object key. Note that the final computed Key takes into account the prefix option of the service.
UploadIdthe UploadId generated when calling the createMultipartUpload method.
partsthe uploaded parts. It consists in an array of objects following the schema: { PartNumber: <number>, ETag: <etag> )}.

Any optional properties are forwarded to the underlying CompleteMultipartUploadCommand command parameters.

uploadPart (data, params)

Upload a part to a bucket.

The payload data must contain the following properties:

PropertyDescription
idthe object key. Note that the final computed Key takes into account the prefix option of the service.
UploadIdthe UploadId generated when calling the createMultipartUpload method.
PartNumberthe part number.
bufferthe content to be uploaded.
typethe content type to be uploaded.

putObject (data, params)

Upload an object to a bucket.

The payload data must contain the following properties:

PropertyDescription
idthe object key. Note that the final computed Key takes into account the prefix option of the service.
bufferthe content to be uploaded.
typethe content type to be uploaded.

getObjectCommand (data, params)

Execute the GetObjectCommand and returns the response.

NOTE

This method is not declared on the client side.

The payload data must contain the following properties:

PropertyDescription
idthe object key. Note that the final computed Key takes into account the prefix option of the service.

uploadFile (data, params)

Convenient method to upload a file.

NOTE

This method is not declared on the client side.

The payload data must contain the following properties:

PropertyDescription
filePaththe path to the file to be uploaded. The basename is used for computing the object key.
contentTypethe content type of the file to be uploaded.

NOTE

You can also provide an id property to override the computed object key.

downloadFile (data, params)

Convenient method to download a file.

NOTE

This method is not declared on the client side.

The payload data must contain the following properties:

PropertyDescription
ìdthe file key. Note that the final computed Key takes into account the prefix option of the service.
filePaththe path to the downloaded file.