Skip to contents

Downloads a file attachment from the Referendum Database (RDB). The necessary s3_object_keys identifying individual files are found in the files list column returned by rfrnds().

Usage

download_file_attachment(
  s3_object_key,
  path = ".",
  use_original_filename = FALSE,
  use_testing_server = pal::pkg_config_val(key = "use_testing_server", pkg = this_pkg)
)

Arguments

s3_object_key

Key uniquely identifying the file in the RDB Amazon S3 bucket. A character scalar.

path

Path where the downloaded file is written to.

use_original_filename

Whether to save the file attachment using its original filename as uploaded. Note that original filenames are not unique, i.e. there are multiple file attachments with the same original filename (but differing content, of course). If FALSE, s3_object_key is used as filename. Only relevant if path is a directory.

use_testing_server

Whether or not to use the testing servers instead of the production servers for RDB Services API calls etc.

Value

A response object, invisibly.

See also

Examples

# get object keys
obj_keys <-
  rdb::rfrnds()$files |>
  purrr::list_rbind() |>
  dplyr::filter(!is_deleted) |>
  _$s3_object_key[1:3]

# download them to the current working dir
purrr::walk(obj_keys,
            rdb::download_file_attachment)

# and delete them again
fs::file_delete(obj_keys)