Learn R Programming

aws.s3 (version 0.2.2)

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.
Additional arguments passed to s3HTTP.
file
An R connection, or file name specifying the local file to save the object into.

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 as a raw vector. 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”. Some users may find the raw vector response format of get_object unfamiliar. The object will also carry attributes, including “content-type”, which may be useful for deciding how to subsequently process the vector. Two common strategies are as follows. For text content types, running charToRaw may be the most useful first step to make the response human-readable. Alternatively, converting the raw vector into a connection using rawConnection may also be useful, as that can often then be passed to parsing functions just like a file connection would be.

References

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

See Also

get_bucket, put_object, delete_object, 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 <- save_object(obj[[1]], file = object[[1]][["Key"]])
#   y %in% dir()
# 
#   # return object using 'S3 URI' syntax
#   get_object("s3://myexamplebucket/mtcars")
# 
#   # return parts of an object
#   ## use 'Range' header to specify bytes
#   get_object(object = obj[[1]], headers = list('Range' = 'bytes=1-120'))
## ---------------------------------------------

Run the code above in your browser using DataLab