from seatable_api import Base, context
# 定义服务器URL和API Token
server_url = context.server_url or 'https://cloud.seatable.cn'
api_token = '2eba3e3ebe*************131ca28b453'
# 初始化并授权Base对象
base = Base(api_token, server_url)
base.auth()
# 定义文件信息(手动构造info_dict)
file_url = 'https://cloud.seatable.cn/workspace/343441/asset-preview/6ba*******843c063f1/custom/ces/1%E5%8F%B7.pdf'
file_name = '1号.pdf'
info_dict = {
"url": file_url,
"name": file_name,
"type": "file"
}
# 获取目标表格的数据
table_name = 'Table2'
rows = base.list_rows(table_name)
# 遍历表格中的每一行,查找名称列中与文件名相同的条目
for row in rows:
if row['名称'] == file_name: # 假设"名称"列的列名为"名称"
row_id = row['_id']
# 打印现有文件列内容
print(f"Existing file column content: {row.get('文件')}")
# 更新文件单元格
if '文件' in row and row['文件']:
row['文件'].append(info_dict)
else:
row['文件'] = [info_dict]
# 打印将要更新的数据
print(f"Updated file column content: {row['文件']}")
# 更新该行
result = base.update_row(table_name, row_id, {"文件": row['文件']})
print(f"Update result: {result}")
print(f"Updated row {row_id} with file {file_name}")
print("File update complete.")
# 再次获取该行的数据以验证更新
updated_row = base.get_row(table_name, row_id)
print(f"Verified updated row: {updated_row}")
我换成系统文件夹里的文件存储URL也是一样无法更新到表格中Existing file column content: None Updated file column content: [{'url': 'https://cloud.seatable.cn/workspace/343441/asset-preview/6baa************43c063f1/files/2024-08/1%E5%8F%B7.pdf', 'name': '1号.pdf', 'type': 'file'}] Update result: {'success': True} Updated row AkVpAUsPRS6hpX9hKR-Rwg with file 1号.pdf File update complete. Verified updated row: {'URL': None, '_archived': False, '_creator': '0894f7c77b1a4253b2eef8b5c9985c47@auth.local', '_ctime': '2024-08-26T09:25:11.528+08:00', '_id': 'AkVpAUsPRS6hpX9hKR-Rwg', '_last_modifier': '上传', '_locked': None, '_locked_by': None, '_mtime': '2024-08-26T10:20:00+08:00', '名称': '1号.pdf', '图片': None, '文件': None}
file_url = 'https://cloud.seatable.cn/workspace/343441/asset-preview/6baa6**********43c063f1/files/2024-08/1号.pdf’也不行,用file_url = 'files/2024-08/1%E5%8F%B7.pdf’也不行,还是无法更新到表格