R/attach_file_to_resource.R

Defines functions attach_file_to_resource

Documented in attach_file_to_resource

#' attach_file_to_node
#'
#' Attach a file to an existing resource
#'
#' @param resource_nid character: Data Catalog Resource Node ID
#' @param file_path character: Path to file on local machine
#' @param root_url character: API root URL
#' @param credentials Optional list parameter. Default values are Cookie and Token generated by dkan_setup()
#' @param attach numeric: Setting the attach parameter to 0 ensures that the file will replace any existing file on the resource. Setting it to 1 will result in a rejected request if the resource already has an attached file (but it will work if the resource file upload field is empty).
#'
#' @export
#'

attach_file_to_resource <- function(resource_nid,
                                    file_path,
                                    root_url = dkanr::get_url(),
                                    credentials = list(cookie = dkanr::get_cookie(),
                                                       token = dkanr::get_token()),
                                    attach = 1){
      out <- dkanr::attach_file_to_node(nid = resource_nid,
                            url = root_url,
                            credentials = credentials,
                            file_path = file_path,
                            attach = attach)

      return(out)
}
tonyfujs/ddhconnect documentation built on June 3, 2020, 10:33 a.m.