Skip to content

Instantly share code, notes, and snippets.

@mayneyao
Created February 7, 2022 11:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayneyao/2a977e3fd89a1d7ce1010d8142676b08 to your computer and use it in GitHub Desktop.
Save mayneyao/2a977e3fd89a1d7ce1010d8142676b08 to your computer and use it in GitHub Desktop.
批量上传附件到维格表
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