Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2020-12-07 09:54 AM
Hi folks,
I have some issues with the Base64 encoded data, I was able to successfully upload the attachment to the archer record, however the Issue is with the attached files in the archer record.The Attached files are always getting corrupted and not coming exactly what I encoded.
Here is my code:
$path = "C:\Attachments\Test.pdf"
$content = Get-Content -Path $path
#$content
$bytes = [System.Text.Encoding]::UTF8.GetBytes($content)
$base64 = [System.Convert]::ToBase64String($bytes)
$base64
$body_upload = @"
{
`"AttachmentName`": `"Test.pdf`",
`"AttachmentBytes`": `"$base64`"
}
"@
$results = Invoke-RestMethod -Method POST -Uri $api_url -Headers $headers -Body $body_upload -ContentType "application/json"
if ($results.IsSuccessful -and $results.ValidationMessages.count -eq 0) {
$results.RequestedObject
$File_ID = $results.RequestedObject.Id
# "File ID = " + $File_ID
}
else {
$results.ValidationMessages
}
$file_body = "{
`"Content`": {
`"Id`": 462209,
`"LevelId`": 62,
`"Tag`": `"Findings`",
`"FieldContents`": {
`"16597`": {
`"Type`": 11,
`"Tag`": `"Attachments`",
`"Value`": [$File_ID],
`"FieldId`": 16597
}
}
}
}"
$response = Invoke-RestMethod -Method PUT -Uri $contentupdate_url -Headers $headers -Body $file_body -ContentType "application/json"
2020-12-07 11:04 AM
Thanks David.
Found the issue.
Changed 2nd line and it's working.
$content = Get-Content -raw $path
2020-12-07 10:23 AM
I wonder if the UTF8.GetBytes is causing the issue.
Advisory Consultant
2020-12-07 11:04 AM
Thanks David.
Found the issue.
Changed 2nd line and it's working.
$content = Get-Content -raw $path
2021-11-23 08:16 AM
Does the attachment work with a user account only has the application access and the record permission? or does it need a sysadmin access to attach a file through an API?