For anyone that finds this post in the future, this app solves for this kind of thing natively in the UI using workflow actions: HubSpot Marketplace
While not the actual code necessary to do this, the app solves teh use case of attaching files to objects.