以下代码是Python Quickbase模块的一部分,该模块在很长一段时间内尚未更新。下面显示的其中一个函数的帮助文本不清楚如何传递参数来上传文件(其值实际上是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'])
有人可以帮助我如何传递参数来添加记录。
答案 0 :(得分:1)
根据您提供的定义,您似乎需要传递一个字典数组,每个字典都提供uploads
参数的文件的字段名称/ id,文件名和base64编码。所以,如果我有一个表格,我将一个颜色的名称记录到名为“color”的字段,字段id为19,样本图像记录到名为“sample image”的字段,字段id为21,我相信我的方法调用类似于:
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)
或者,如果您使用的是字段名称:
my_color_file = #base64 encoding of your file
my_fields = {'color': 'Seafoam Green'}
my_uploads = [{'field': 'sample_image', 'filename':'seafoam_green.png', 'value': my_color_file}]
client.add_record(fields=my_fields, named=True, uploads=my_uploads)
client
只是您之前使用此模块具有的任何构造函数实例化的对象。