Skip to contents

[Experimental]

Usage

attachment_upload(
  iid,
  filename,
  file,
  content_type = NULL,
  pid = get_default_pid(),
  fid = get_default_fid(),
  url = get_default_url(),
  un = get_default_un(),
  pw = get_default_pw(),
  retries = get_retries()
)

Arguments

iid

The instance_id, a UUID, as returned by submission_list.

filename

(character) The name of the file as given by the attachment listing resource, e.g. "file1.jpg".

file

(character) Path to a local file whose bytes are uploaded to the expected file slot.

content_type

(character) The MIME type sent as Content-Type header, e.g. "image/jpeg". Default: NULL, which sends "application/octet-stream".

pid

The numeric ID of the project, e.g.: 2.

Default: get_default_pid.

Set default pid through ru_setup(pid="...").

See vignette("Setup", package = "ruODK").

fid

The alphanumeric form ID, e.g. "build_Spotlighting-0-8_1559885147".

Default: get_default_fid.

Set default fid through ru_setup(fid="...").

See vignette("Setup", package = "ruODK").

url

The ODK Central base URL without trailing slash.

Default: get_default_url.

Set default url through ru_setup(url="...").

See vignette("Setup", package = "ruODK").

un

The ODK Central username (an email address). Default: get_default_un. Set default un through ru_setup(un="..."). See vignette("Setup", package = "ruODK").

pw

The ODK Central password. Default: get_default_pw. Set default pw through ru_setup(pw="..."). See vignette("Setup", package = "ruODK").

retries

The number of attempts to retrieve a web resource.

This parameter is given to RETRY(times = retries).

Default: 3.

Value

A list with a single element success (TRUE) as per the ODK Central API docs.

Details

To upload a binary to an expected file slot, POST the binary to its endpoint. The expected file slots are determined by the Submission XML; list them with attachment_list(). filename must match a slot name from the attachment listing. file is the local file. Its bytes fill the slot.

Examples

if (FALSE) { # \dontrun{
# See vignette("setup") for setup and authentication options
# ruODK::ru_setup(svc = "....svc", un = "me@email.com", pw = "...")

sl <- submission_list()
iid <- sl$instance_id[[1]]

al <- attachment_list(iid)
al$name
# > "photo.jpg"

attachment_upload(iid, "photo.jpg", "/path/to/photo.jpg")
# > $success
# > [1] TRUE
} # }