Skip to contents

Generic implementing of how to upload files to a connector:

  • ConnectorLogger: Logs the upload operation and calls the underlying connector method.

Usage

upload_cnt(
  connector_object,
  src,
  dest = basename(src),
  overwrite = zephyr::get_option("overwrite", "connector"),
  ...
)

# S3 method for class 'ConnectorFS'
upload_cnt(
  connector_object,
  src,
  dest = basename(src),
  overwrite = zephyr::get_option("overwrite", "connector"),
  ...
)

# S3 method for class 'ConnectorLogger'
upload_cnt(
  connector_object,
  src,
  dest = basename(src),
  overwrite = zephyr::get_option("overwrite", "connector"),
  ...
)

Arguments

connector_object

Connector The connector object to use.

src

character Path to the file to download to or upload from

dest

character Name of the content to read, write, or remove. Typically the table name.

overwrite

Overwrite existing content if it exists in the connector? See connector-options for details. Default can be set globally with options(connector.overwrite = TRUE/FALSE) or environment variable R_CONNECTOR_OVERWRITE.. Default: FALSE.

...

Additional arguments passed to the method for the individual connector.

Value

invisible connector_object.

Examples

# Upload file to a file storage

writeLines("this is an example", "example.txt")

folder <- withr::local_tempdir()
cnt <- connector_fs(folder)
#> Error in validate_resource(self): Invalid file system connector: /tmp/RtmplxpBaF/file1e845e8d53c3 does not
#> exist.

cnt |>
  list_content_cnt(pattern = "example.txt")
#> Error: object 'cnt' not found

cnt |>
  upload_cnt("example.txt")
#> Error: object 'cnt' not found

cnt |>
  list_content_cnt(pattern = "example.txt")
#> Error: object 'cnt' not found

cnt |>
  remove_cnt("example.txt")
#> Error: object 'cnt' not found

file.remove("example.txt")
#> [1] TRUE

# Add logging to a file system connector for uploads
folder <- withr::local_tempdir()
cnt <- connectors(data = connector_fs(folder)) |> add_logs()
#> Error in validate_resource(self): Invalid file system connector: /tmp/RtmplxpBaF/file1e841444b0eb does not
#> exist.

# Create a temporary file
temp_file <- tempfile(fileext = ".csv")
write.csv(iris, temp_file, row.names = FALSE)

cnt$data |>
  upload_cnt(temp_file, "uploaded_iris.csv")
#> Error: object 'cnt' not found