【seatable】上传图片代码过程

我们首先来说明一下,当上传一个图片,我们看一下rows的东西。
关于rows的array结构,在上一篇文章说过。

在这里插入图片描述
rows输出如下json in array structure data type.

[{
‘name’: ‘第一行’,
‘age’: ‘799’,
‘file’: [{
‘name’: ‘IMG_5157.jpg’,
‘size’: 72591,
‘type’: ‘file’,
‘upload_time’: ‘2024-04-10T05:50:07.168+00:00’,
‘url’: ‘https://cloud.seatable.cn/workspace/xxxxxx/asset/c2645e9b-6cf3-40xxxxxxxba4/files/2024-04/IMG_5157.jpg’
}],
‘_locked’: None,
‘_locked_by’: None,
‘_archived’: False,
‘_creator’: ‘ed2fa69d@auth.local’,
‘_ctime’: ‘2024-04-10T10:41:36.157+08:00’,
‘_last_modifier’: ‘ed9d@auth.local’,
‘_mtime’: ‘2024-04-10T13:50:08+08:00’,
‘_id’: ‘Bla1K4zbRJ2KKmOMWPs3AA’
}, {
‘name’: ‘第二行’,
‘age’: ‘12212’,
‘file’: None,
‘_locked’: None,
‘_locked_by’: None,
‘_archived’: False,
‘_creator’: None,
‘_ctime’: ‘2024-04-10T11:22:57.49+08:00’,
‘_last_modifier’: ‘e@auth.local’,
‘_mtime’: ‘2024-04-10T13:49:53+08:00’,
‘_id’: ‘OYadXt_uTDK4h4ww4v-zCA’
}]

我们可以看到,在rows的array中,file的key又嵌套了一个array
在这里插入图片描述
提取出来的key-value pair 如下structure:

‘file’: [{
‘name’: ‘IMG_5157.jpg’,
‘size’: 72591,
‘type’: ‘file’,
‘upload_time’: ‘2024-04-10T05:50:07.168+00:00’,
‘url’: ‘https://cloud.seatable.cn/workspace/xxxxxx/asset/xxxx-6xxxx9ba4/files/2024-04/IMG_5157.jpg’
}],

其中[]belong to array的marker,{}belong to dictionary.
我们看到file的value中有一个 url,生成一了一个https的link
这个link是要怎么加进去的呢?
官方给出的以下代码:
正常在row 中插入代码

append_row
update_row

row_data = {'name': 'Tom', 'age': 18}
# 追加行
base.append_row('Table1', {'name': 'Tom', 'age': 18})
# 更新行
base.update_row('Table1', 'U_eTV7mDSmSd-K2P535Wzw', {'name': 'Tom', 'age': 18})

引入图片的代码

base.update_row(‘Table1’, row_id, {“file”: [info_dict]})
其中这个info_dict包含了URL
print(info_dict)
{
‘type’: ‘file’,
‘size’: 34857,
‘name’: ‘IMG_5420 (5).jpg’,
‘url’: ‘https://cloud.seatable.cn/workspace/333/asset/3-403/files/2024-04/IMG_5420%20%285%29.jpg’
}

info_dict引入一个函数base.upload_local_file

file_path = './IMG_5420.jpg'
info_dict=base.upload_local_file(file_path, name=None, file_type='file', replace=False)
print(info_dict)

再使用base.update_row('Table1', row_id, {"file": [info_dict]})
效果达成。

  • 12
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值