2014-04-26 45 views
2

我使用beatbox和python将文档上传到Salesforce,并且文件连接正确,但文件中包含的数据完全损坏。通过Beatbox上传附件到Salesforce API

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并查看该文件的文件的内容是:

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

我不知道是什么原因导致了这个问题,我找不到发生在其他人身上的任何情况

链接到SFDC Documentation on uploads

回答

2

在字典中的“体”值应编码的文件,而不是文件名的内容的BASE64。你需要自己读取和编码文件内容。例如

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