Learn R Programming

aws.s3 (version 0.1.34)

get_object: Get object

Description

Retrieve an object from an S3 bucket

Usage

get_object(object, bucket, headers = list(), parse_response = FALSE, ...)
save_object(object, bucket, file, headers = list(), ...)
head_object(object, bucket, ...)

Arguments

object
Character string with the object key, or an object of class “s3_object”. In most cases, if object is specified as the latter, bucket can be omitted because the bucket name will be extracted from “Bucket” slot in object.
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.
parse_response
Passed through to s3HTTP, as this function requires a non-default setting. There is probably no reason to ever change this.
file
An R connection, or file name specifying the local file to save the object into.
...
Additional arguments passed to s3HTTP.

Value

If file = NULL, a raw object. Otherwise, a character string containing the file name that the object is saved to.

Details

get_object retrieves an object into memory. save_object saves an object to a local file. head_object checks whether an object exists by executing an HTTP HEAD request; this can be useful for checking object headers such as “content-length” or “content-type”.

References

API Documentation: GET Object

API Document: HEAD Object

See Also

get_bucket, s3curl

Examples

Run this code
## Not run: 
# # get an object in memory
# ## create bucket
# b <- put_bucket("myexamplebucket")
# ## save a dataset to the bucket
# s3save(mtcars, bucket = b, object = "mtcars")
# obj <- get_bucket(b)
# ## get the object in memory
# x <- get_object(obj[[1]])
# load(rawConnection(x))
# "mtcars" %in% ls()
# 
# # save an object locally
# y <- get_object(obj[[1]], file = object[[1]][["Key"]])
# y %in% dir()
# 
# # return parts of an object
# ## use 'Range' header to specify bytes
# get_object(object = obj[[1]], headers = list('Range' = 'bytes=1-120'))
# ## End(Not run)

Run the code above in your browser using DataLab