<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def upload(self, sys_id, file_path, name=None, multipart=False):
 """Attaches a new file to the provided record :param sys_id: the sys_id of the record to attach the file to :param file_path: local absolute path of the file to upload :param name: custom name for the uploaded file (instead of basename) :param multipart: whether or not to use multipart :return: the inserted record """


        if not isinstance(multipart, bool):
            raise InvalidUsage('Multipart must be of type bool')

        resource = self.resource

        if name is None:
            name = os.path.basename(file_path)

        resource.parameters.add_custom({
            'table_name': self.table_name,
            'table_sys_id': sys_id,
            'file_name': name
        })

        data = open(file_path, 'rb').read()
        headers = {}

        if multipart:
            headers["Content-Type"] = "multipart/form-data"
            path_append = '/upload'
        else:
            headers["Content-Type"] = "text/plain"
            path_append = '/file'

        return resource.request(method='POST', data=data, headers=headers, path_append=path_append)