Navigation

s3Service.put()

On this page

Definition

s3Service.put(args)

Uploads binary data to an S3 bucket.

Important

To perform an S3 service action, you must have rules set up for the action.

The s3Service.put() function takes the following parameter:

Parameter Type Description
args document
{
    "bucket": <string>,
    "key": <string>,
    "contentType": <string>,
    "acl": <string>,
    "body": <mixed>
}

The fields of args are as follows:

Argument Type Description
bucket string The S3 bucket name.
key string The unique identifier for the uploaded object.
acl string

Access control list. Valid values are:

  • private
  • public-read
  • public-read-write
  • aws-exec-read
  • authenticated-read
  • bucket-owner-read
  • bucket-owner-full-control

See Amazon’s documentation for more information.

contentType string Data format, e.g. text/plain
body string or binary The data to upload.
Returns:A document of the following form:
{
    "location": <string>
}

The location field corresponds to the URL of the bucket.

Example

The following function stores the text “Hello World!” in a bucket. test hi!

exports = function(){
  var s3Service = context.services.get("my-s3-service");
  return s3Service.put({
    "bucket": "bucket-name",
    "key": "content-key",
    "contentType": "text/plain",
    "acl": "public-read",
    "body": "Hello World!"
  })
};

This example assumes that an S3 service has been created with the name “my-s3-service”. Executing this function returns a document resembling the following:

{
    "location": "https://stitch-example.s3.us-east-2.amazonaws.com/content-key"
}