| add_attachments | R Documentation |
Query attachment information using query_layer_attachments() and
download attachments using download_attachments().
Feature Services can contain attachments that are associated with a single feature ID.
Use add_features() to add attachments to a feature service
Use update_features() to update the attachments of a feature service
Use query_layer_attachments() to list attachments of a feature service
Use download_attachments() with the results of query_layer_attachments()
to download the attachments from a feature service locally
add_attachments(
x,
feature_id,
path,
file_name = basename(path),
.progress = TRUE,
token = arc_token()
)
query_layer_attachments(
x,
definition_expression = "1=1",
attachments_definition_expression = NULL,
object_ids = NULL,
global_ids = NULL,
attachment_types = NULL,
keywords = NULL,
return_metadata = TRUE,
...,
token = arc_token()
)
download_attachments(
attachments,
out_dir,
...,
overwrite = FALSE,
.progress = TRUE,
token = arc_token()
)
update_attachments(
x,
feature_id,
attachment_id,
path,
.progress = TRUE,
token = arc_token()
)
x |
an object of class |
feature_id |
a vector of object IDs that corresponds to the feature of the corresponding |
path |
a vecetor of the same length as |
file_name |
the name of the file. Defaults to the |
.progress |
default |
token |
an |
definition_expression |
default |
attachments_definition_expression |
default |
object_ids |
mutually exclusive with |
global_ids |
mutally exclusive with |
attachment_types |
default |
keywords |
default |
return_metadata |
default |
... |
unused |
attachments |
a |
out_dir |
the path to the folder to download the file |
overwrite |
default |
attachment_id |
the ID of the attachment—this corresponds to the |
To rename or otherwise modify an attachment in a Feature Service, you must first download
that attachment, modify the file on disk, and then upload it again. This is a limitation
of ArcGIS Online and Enterprise. If you'd like to see this changed, please submit a community idea at community.esri.com.
If any requests fail, the requests are added as as the errors attribute to the resultant data.frame.
query_layer_attachments() returns a data.frame.
download_attachments() returns a list. If an error occurs, the condition is captured and returned in the list.
Otherwise the path to the file that was downloaded is returned.
a data.frame with 2 columns returning the status of the update.
See API documentation for more.
See API documentation for more.
## Not run:
if (interactive()) {
library(arcgisutils)
# authenticate
set_arc_token(auth_user())
# open a feature service
feature_layer <- arc_open("your-item-id") |>
# layer ID of the feature service
get_layer(0)
# create a list of features to update
features <- c(1,2,3)
# create a list of files to upload as attachments
attachment_files <- c("path/to/file1.png", "path/to/file2.png", "path/to/file3.png")
# add the attachment files to the features in the feature layer
add_response <- add_attachments(feature_layer, features, attachment_files, use_basename=TRUE)
}
## End(Not run)
## Not run:
# create a url path that isn't too wide for CRAN
furl <- paste(
c(
"https://services1.arcgis.com/hLJbHVT9ZrDIzK0I",
"arcgis/rest/services/v8_Wide_Area_Search_Form_Feature_Layer___a2fe9c",
"FeatureServer/0"
),
collapse = "/"
)
# connect to the layer
layer <- arc_open(furl)
# get the attachment info
att <- query_layer_attachments(layer)
# download them to a path
download_attachments(att, "layer_attachments")
## End(Not run)
## Not run:
if (interactive()) {
library(arcgisutils)
# authenticate
set_arc_token(auth_user())
# open a feature service
feature_layer <- arc_open("your-item-id") |>
# layer ID of the feature service
get_layer(0)
# query attachment layer information
attachments <- query_layer_attachments(feature_layer)
# create a temporary directory
tmp <- tempdir()
# download attachments to the temporary directory
download_attachments(attachments, tmp)
# get original paths
fps <- file.path(tmp, attachments$name)
# prepend attachments with the date
new_filenames <- paste0(Sys.Date(), "-", basename(attachments$name))
# create new file paths
new_fps <- file.path(dirname(fps), new_filenames)
# rename the files
file.rename(fps, new_fps)
# update the attachments
update_res <- update_attachments(
feature_layer,
# OID of the feature <> attachment relationship
attachments$parentObjectId,
# the attachment ID
attachments$id,
# the path to the attachment on disk
new_fps
)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.