上传附件到Salesforce API通过Beatbox和Python

2024-06-12 08:02:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用beatbox和python将文档上载到Salesforce,文件正确附加,但文件中包含的数据完全损坏。在

def Send_File():
    import beatbox
    svc = beatbox.Client()  # instantiate the object
    svc.login(login1, pw1)  # login using your sf credentials

    update_dict = {
        'type':'Attachment',
        'ParentId': accountid,
        'Name': 'untitled.txt',
        'body':'/Users/My_Files/untitled.txt',
            }
    results2 = svc.create(update_dict)
    print results2

输出为:

^{pr2}$

所以事情进展顺利,但是当我去salesforce记录00Pi0000005ek6gEAA并查看该文件时,该文件的内容是:

   ˝KÆœ  Wøä ï‡Îä˜øHÅCj÷øaÎ0j∑ø∫{b∂Wù

我不知道是什么导致了这个问题,我也找不到其他人发生过这种情况

链接到SFDC Documentation on uploads


Tags: 文件数据文档txtsenddefloginupdate
1条回答
网友
1楼 · 发布于 2024-06-12 08:02:45

字典中的“body”值应该是文件的base64编码内容,而不是文件名。您需要自己读取和编码文件内容。e、 g

body = ""
with open("/Users/My_Files/untitled.txt", "rb") as f:
    body = f.read().encode("base64")

update_dict = {
    'type' : 'Attachement'
    'ParentId' : accountId,
    'Name' : 'untitled.txt',
    'Body' : body }

...

关于Attachment的文档

相关问题 更多 >