通过Beatbox,Python将附件上传到Salesforce API [英] Uploading Attachments to Salesforce API via Beatbox, Python

查看:100
本文介绍了通过Beatbox,Python将附件上传到Salesforce API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Beatbox和python将文档上传到Salesforce,并且文件正确附加,但是文件中包含的数据完全损坏了.

I'm uploading documents to Salesforce using beatbox and python and the files are attaching correctly but the data contained within the files gets completely corrupted.

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

输出为:

    00Pi0000005ek6gEAAtrue

一切顺利,但是当我转到salesforce记录00Pi0000005ek6gEAA并查看文件时,该文件的内容为:

So things are coming through well, but when I go to the salesforce record 00Pi0000005ek6gEAA and view the file the contents of the file are:

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

我不知道是什么原因引起的,我也找不到其他情况发生的任何情况

I have no clue what's causing the issue and I can't find any situations where this has happened to other people

链接 上传的SFDC文档

推荐答案

字典中的"body"值应为文件的base64编码内容,而不是文件名.您需要自己阅读和编码文件内容.例如

the 'body' value in the dictionary should be the base64 encoded contents of the file, not the file name. you need to read and encode the file contents yourself. 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 }

...

关于附件

这篇关于通过Beatbox,Python将附件上传到Salesforce API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆