This function will allow you to download an attachment to disk based on the attachment body, file name, and path.
sf_download_attachment(
body,
name = NULL,
sf_id = NULL,
object_name = c("Attachment", "Document"),
path = "."
)
character
; a URL path to the body of the attachment in
Salesforce, typically retrieved by sf_query
on the Attachment
object. Alternatively, you can specify the Salesforce Id of the Attachment.
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 left NULL
, 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.
character
; a Salesforce generated Id that uniquely
identifies a record.
character
; the name of the Salesforce object that the
function is operating against (e.g. "Account", "Contact", "CustomObject__c").
character
; a directory path where to create file, defaults
to the current directory.
character
; invisibly return the file path of the downloaded
content
Other Attachment functions:
check_and_encode_files()
,
sf_create_attachment()
,
sf_delete_attachment()
,
sf_update_attachment()
if (FALSE) {
# 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])
}