Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
批量上传附件到维格表
import os
import time
from vika import Vika
API_TOKEN = '你的 api token'
DST_ID = '存储图片的表id'
file_dir = '/Users/mayne/Desktop/demo' # 需要上图片的文件路径
vika = Vika(API_TOKEN)
# 通过 datasheetId 来指定要从哪张维格表操作数据。
datasheet = vika.datasheet(DST_ID, field_key="name")
for name in os.listdir(file_dir):
filepath = os.path.join(file_dir, name)
if os.path.isfile(filepath):
_file = datasheet.upload_file(filepath)
new_record = datasheet.records.create({
'title': name, # 换成你的表对应的任意文本字段(可以不要这个)
'files': [_file], # 换成你的表对应的任意附件字段
})
print(new_record.files)
time.sleep(1 / 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment