code: def attach(self, api_object, on_cloud=False):
          
  
          if self.on_cloud:
              # item is already saved on the cloud.
              return True
  
          # api_object must exist and if implements attachments
          # then we can attach to it.
          if api_object and getattr(api_object, 'attachments', None):
              if on_cloud:
                  if not api_object.object_id:
                      raise RuntimeError(
                          'A valid object id is needed in order to attach a file')
                  # api_object builds its own url using its
                  # resource and main configuration
                  url = api_object.build_url(self._endpoints.get('attach').format(
                      id=api_object.object_id))
  
                  response = api_object.con.post(url, data=self.to_api_data())
  
                  return bool(response)
              else:
                  if self.attachment_type == 'file':
                      api_object.attachments.add([{
                          'attachment_id': self.attachment_id,
                          # TODO: copy attachment id? or set to None?
                          'path': str(
                              self.attachment) if self.attachment else None,
                          'name': self.name,
                          'content': self.content,
                          'on_disk': self.on_disk
                      }])
                  else:
                      raise RuntimeError('Only file attachments can be attached')
docs: Attach this attachment to an existing api_object. This
          BaseAttachment object must be an orphan BaseAttachment created for the
          sole purpose of attach it to something and therefore run this method.
  
          :param api_object: object to attach to
          :param on_cloud: if the attachment is on cloud or not
          :return: Success / Failure
          :rtype: bool