Question - download attachments using REST

today someone asked us how to download internal controls / audit / evidence automatically to feed some system of theirs. the typical use case is the opposite, automate evidence upload not download … but is good we got asked to see how to do this.

it does not work btw, there is a small change needed but that small change could mess up other things so this is a bit experimental.

on demo-e2 i have audits and i put attachments (a csv file) on audit id 1

if you want to know “what attachment has audit id = 1” you need to query the attachment plugin (the same as you would do if you upload an attachment) with a get request:

https://demo-e2.eramba.org/attachments/attachments/index/securityServiceAudit/1.json

that will get you the attachments for that model id’s … the output will include the file type (important) and id of the attachment, 14 in this case

then you could try to download the attachment … but it wont work out of the box because an exception on the code wont let you do it

https://demo-e2.eramba.org/attachments/attachments/downloadAttachment/14.json

will get you…

if you override the exception on the appcontroller (line 1321) you will be able to download the file

and try again it should work (i have not tested this for binary files)

we need to review this code a bit more in detail after the migration…

int ref: https://eramba.zendesk.com/agent/tickets/10566
int ref: https://github.com/eramba/eramba_v2/issues/2765