# NOT RUN {
library("datasets")
# write file to S3
tmp <- tempfile()
on.exit(unlink(tmp))
utils::write.csv(mtcars, file = tmp)
# put object with an upload progress bar
put_object(tmp, object = "mtcars.csv", bucket = "myexamplebucket", show_progress = TRUE)
# create a "folder" in a bucket
put_folder("example", bucket = "myexamplebucket")
## write object to the "folder"
put_object(tmp, object = "example/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
## encryption can also be set at the bucket-level using \code{\link{put_encryption}}
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")))
# multi-part uploads for objects over 5MB
\donttest{
x <- rnorm(3e6)
saveRDS(x, tmp)
put_object(tmp, object = "rnorm.rds", bucket = "myexamplebucket",
show_progress = TRUE, multipart = TRUE)
identical(x, s3readRDS("s3://myexamplebucket/rnorm.rds"))
}
# }
Run the code above in your browser using DataLab