Skip to contents

Magically upload a file

Usage

six_file_upload(path, bucket, force = FALSE, ...)

Arguments

path

(character) one or more file paths to add to the bucket. required. cannot include directories

bucket

(character) bucket to copy files to. required. if the bucket does not exist we prompt you asking if you'd like the bucket to be created

force

(logical) force bucket creation without going through the prompt. default: FALSE. Should only be set to TRUE when required for non-interactive use.

...

named params passed on to put_object

Value

(character) a vector of remote s3 paths where your files are located

What is magical

  • Exits early if files do not exist

  • Exits early if any path values are directories

  • Creates the bucket if it does not exist

  • Adds files to the bucket, figuring out the key to use from the supplied path

  • Function is vectoried for the path argument; you can pass in many file paths

Examples

if (FALSE) { # interactive()
bucket <- random_string("bucket")
demo_rds_file <- file.path(system.file(), "Meta/demo.rds")
six_file_upload(demo_rds_file, bucket)

## many files at once
links_file <- file.path(system.file(), "Meta/links.rds")
six_file_upload(c(demo_rds_file, links_file), bucket)

# set expiration, expire 1 minute from now
six_file_upload(demo_rds_file, bucket, Expires = Sys.time() + 60)

# bucket doesn't exist, ask if you want to create it
six_file_upload(demo_rds_file, "not-a-buckets")

# path doesn't exist
# six_file_upload("file_doesnt_exist.txt", random_string("bucket"))

# directories not supported
mydir <- tempdir()
# six_file_upload(mydir, random_string("bucket"))
}