Quickbase模块add_record()函数文件上传参数?

2024-04-20 13:28:13 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的代码是pythonquickbase模块的一部分,已经有很长时间没有更新了。下面显示的函数之一的帮助文本不清楚如何传递参数来上载文件(文件的值实际上是base64编码的)。在

def add_record(self, fields, named=False, database=None, ignore_error=True, uploads=None):
    """Add new record. "fields" is a dict of name:value pairs
    (if named is True) or fid:value pairs (if named is False). Return the new records RID
    """
    request = {}
    if ignore_error:
        request['ignoreError'] = '1'
    attr = 'name' if named else 'fid'
    request['field'] = []
    for field, value in fields.iteritems():
        request_field = ({attr: to_xml_name(field) if named else field}, value)
        request['field'].append(request_field)
    if uploads:
        for upload in uploads:
            request_field = (
                {attr: (to_xml_name(upload['field']) if named else upload['field']),
                 'filename': upload['filename']}, upload['value'])
            request['field'].append(request_field)

    response = self.request('AddRecord', database or self.database, request, required=['rid'])
    return int(response['rid'])

有人能帮助我如何传递参数来添加记录吗。在


Tags: nameselffieldfields参数ifisvalue
1条回答
网友
1楼 · 发布于 2024-04-20 13:28:13

根据您提供的定义,您似乎需要传递一个字典数组,每个字典都提供uploads参数的字段名/id、文件名和文件的base64编码。因此,如果我有一个表,其中我将颜色的名称记录到名为“color”的字段,字段id为19,将示例图像记录到字段id为21的“sample image”字段中,我相信我的方法调用如下所示:

my_color_file = #base64 encoding of your file
my_fields = {'19': 'Seafoam Green'}
my_uploads = [{'field': 21, 'filename':'seafoam_green.png', 'value': my_color_file}]
client.add_record(fields=my_fields, uploads=my_uploads)

或者,如果使用字段名:

^{pr2}$

client只是您先前使用此模块拥有的任何构造函数实例化的对象。在

相关问题 更多 >