Learn R Programming

aws.s3 (version 0.2.2)

put_object: Put object

Description

Puts an object into an S3 bucket

Usage

put_object(file, object, bucket, 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”.
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

http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html

See Also

put_bucket, get_object, delete_object

Examples

Run this code
## Not run: ------------------------------------
#   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")
# 
#   # 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