This function will allow you to download an attachment to disk based on the attachment body, file name, and path.
Usage
sf_download_attachment(
body,
name = NULL,
sf_id = NULL,
object_name = c("Attachment", "Document"),
path = "."
)
Arguments
- body
character
; a URL path to the body of the attachment in Salesforce, typically retrieved bysf_query
on the Attachment object. Alternatively, you can specify the Salesforce Id of the Attachment.- name
character
; the name of the file you would like to save the content to. Note that you should include the file extension in this name and if this argument is leftNULL
, then a query will be made to determine the name and file extension needed. This process may result in a slower download process, so attempt to provide the body and name arguments whenever possible for the best performance.- sf_id
character
; a Salesforce generated Id that uniquely identifies a record.- object_name
character
; the name of the Salesforce object that the function is operating against (e.g. "Account", "Contact", "CustomObject__c").- path
character
; a directory path where to create file, defaults to the current directory.
See also
Other Attachment functions:
check_and_encode_files()
,
sf_create_attachment()
,
sf_delete_attachment()
,
sf_update_attachment()
Examples
if (FALSE) { # \dontrun{
# downloading all attachments for a Parent record
# if your attachment name doesn't include the extension, then you can use the
# ContentType column to append it to the Name, if needed
queried_attachments <- sf_query("SELECT Id, Body, Name, ContentType
FROM Attachment
WHERE ParentId = '0016A0000035mJ5'")
mapply(sf_download_attachment, queried_attachments$Body, queried_attachments$Name)
# downloading an attachment by its Id
# (the file name will be the same as it exists in Salesforce)
sf_download_attachment(sf_id = queried_attachments$Id[1])
} # }