Learn R Programming

aws.s3 (version 0.3.1)

put_object: Put object

Description

Puts an object into an S3 bucket

Usage

put_object(file, object, bucket, multipart = FALSE, headers = list(), ...)

Arguments

file

A character string containing the filename (or full path) of the file you want to upload to S3. Alternatively, an raw vector containing the file can be passed directly, in which case object needs to be specified explicitly.

object

A character string containing the name the object should have in S3 (i.e., its "object key"). If missing, the filename is used.

bucket

Character string with the name of the bucket, or an object of class “s3_bucket”.

multipart

A logical indicating whether to use multipart uploads. See http://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html. If file is less than 100 MB, this is ignored.

headers

List of request headers for the REST call.

Additional arguments passed to s3HTTP.

Value

If successful, TRUE.

Details

This provide a generic interface for sending files (or serialized, in-memory representations thereof) to S3. Some convenience wrappers are provided for common tasks: s3save and s3saveRDS.

References

API Documentation

See Also

put_bucket, get_object, delete_object

Examples

Run this code

  library("datasets")

  # write file to S3
  tmp <- tempfile()
  on.exit(unlink(tmp))
  utils::write.csv(mtcars, file = tmp)
  put_object(tmp, object = "mtcars.csv", bucket = "myexamplebucket")

  # write serialized, in-memory object to S3
  x <- rawConnection(raw(0), "w")
  utils::write.csv(mtcars, x)
  put_object(rawConnectionValue(x), object = "mtcars.csv", bucket = "myexamplebucketname")

  # use `headers` for server-side encryption
  ## require appropriate bucket policy
  put_object(file = tmp, object = "mtcars.csv", bucket = "myexamplebucket",
             headers = c('x-amz-server-side-encryption' = 'AES256'))

  # alternative "S3 URI" syntax:
  put_object(rawConnectionValue(x), object = "s3://myexamplebucketname/mtcars.csv")
  close(x)

  # read the object back from S3
  read.csv(text = rawToChar(get_object(object = "s3://myexamplebucketname/mtcars.csv")))

Run the code above in your browser using DataLab