if (FALSE) {
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
)
}
}
Run the code above in your browser using DataLab