Learn R Programming

aws.s3 (version 0.3.21)

head_object: Get object metadata

Description

Check if an object from an S3 bucket exists. To retrieve the object, see get_object

Usage

head_object(object, bucket, ...)

object_exists(object, bucket, ...)

object_size(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”.

Additional arguments passed to s3HTTP.

Value

head_object returns a logical. object_exists returns TRUE if bucket exists and is accessible, else FALSE. object_size returns an integer, which is NA if the request fails.

Details

head_object is a low-level API wrapper that 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”. object_exists is sugar that returns only the logical.

object_size returns the size of the object (from the “content-length” attribute returned by head_object).

References

API Documentation: HEAD Object

See Also

bucket_exists, get_object, put_object, delete_object

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")
  
  # check that object exists
  object_exists("mtcars", "myexamplebucket")
  object_exists("s3://myexamplebucket/mtcars")
  
  # get the object's size
  object_size("s3://myexamplebucket/mtcars")
  
  # get the object
  get_object("s3://myexamplebucket/mtcars")
# }

Run the code above in your browser using DataLab