redcap_upload_file_oneshot {REDCapR}R Documentation

Upload a file into to a REDCap project record

Description

This function uses REDCap's API to upload a file.

Usage

redcap_upload_file_oneshot(
  file_name,
  record,
  redcap_uri,
  token,
  field,
  event = "",
  verbose = TRUE,
  config_options = NULL
)

Arguments

file_name

The name of the relative or full file to be uploaded into the REDCap project. Required.

record

The record ID where the file is to be imported. Required

redcap_uri

The URI (uniform resource identifier) of the REDCap project. Required.

token

The user-specific string that serves as the password for a project. Required.

field

The name of the field where the file is saved in REDCap. Required

event

The name of the event where the file is saved in REDCap. Optional

verbose

A boolean value indicating if messages should be printed to the R console during the operation. Optional.

config_options

A list of options to pass to POST method in the httr package. See the details below. Optional.

Details

Currently, the function doesn't modify any variable types to conform to REDCap's supported variables. See validate_for_write() for a helper function that checks for some common important conflicts.

Value

Currently, a list is returned with the following elements:

Author(s)

Will Beasley, John J. Aponte

References

The official documentation can be found on the 'API Help Page' and 'API Examples' pages on the REDCap wiki (ie, https://community.projectredcap.org/articles/456/api-documentation.html and https://community.projectredcap.org/articles/462/api-examples.html). If you do not have an account for the wiki, please ask your campus REDCap administrator to send you the static material.

Examples

## Not run: 
# Define some constants
uri    <- "https://bbmc.ouhsc.edu/redcap/api/"
token  <- "D70F9ACD1EDD6F151C6EA78683944E98" # The simple project -pid 213
field  <- "mugshot"
event  <- "" # only for longitudinal events

#Upload a single image file.
record    <- 1
file_path <- system.file("test-data/mugshot-1.jpg", package="REDCapR")

REDCapR::redcap_upload_file_oneshot(
  file_name  = file_path,
  record     = record,
  field      = field,
  redcap_uri = redcap_uri,
  token      = token
)

#Upload a collection of five images.
records    <- 1:5
file_paths <- system.file(
  paste0("test-data/mugshot-", records, ".jpg"),
  package="REDCapR"
)

for (i in seq_along(records)) {
  record    <- records[i]
  file_path <- file_paths[i]
  REDCapR::redcap_upload_file_oneshot(
    file_name  = file_path,
    record     = record,
    field      = field,
    redcap_uri = redcap_uri,
    token      = token
  )
}

## End(Not run)

[Package REDCapR version 1.1.0 Index]