def ingest_attachment(self, entity, name, mime_type, body):
    has_body = ((body is not None) and len(body))
    if ((stringify(name) is None) and (not has_body)):
        return
    file_name = safe_filename(name, default='attachment')
    file_path = self.make_work_file(file_name)
    with open(file_path, 'wb') as fh:
        if isinstance(body, str):
            body = body.encode('utf-8')
        if (body is not None):
            fh.write(body)
    checksum = self.manager.store(file_path, mime_type=mime_type)
    file_path.unlink()
    child = self.manager.make_entity('Document', parent=entity)
    child.make_id(name, checksum)
    child.add('contentHash', checksum)
    child.add('fileName', name)
    child.add('mimeType', mime_type)
    self.manager.queue_entity(child)
def ingest_attachment(self, entity, name, mime_type, body):
    has_body = ((body is not None) and len(body))
    if ((stringify(name) is None) and (not has_body)):
        return
    file_name = safe_filename(name, default='attachment')
    file_path = self.make_work_file(file_name)
    with open(file_path, 'wb') as fh:
        if isinstance(body, str):
            body = body.encode('utf-8')
        if (body is not None):
            fh.write(body)
    checksum = self.manager.store(file_path, mime_type=mime_type)
    file_path.unlink()
    child = self.manager.make_entity('Document', parent=entity)
    child.make_id(name, checksum)
    child.add('contentHash', checksum)
    child.add('fileName', name)
    child.add('mimeType', mime_type)
    self.manager.queue_entity(child)