使用 Python 从 Salesforce URL 下载图像 [英] Downloading images from Salesforce URL using Python

查看:47
本文介绍了使用 Python 从 Salesforce URL 下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自 Salesforce 的一系列联系人的 csv,其中包含姓名、位置和打开我需要下载的图像的 URL

到目前为止,我只能使用 Python 访问我的 Salesforce 实例,但我正在努力寻找一种使用 Python 包的方法,不仅可以打开 URL,还可以下载 .jpg 格式的图像并使用客户的姓名和位置.

是否有任何可用的软件包可以让我这样做.我试过使用 simple-salesforce,但我认为它没有这个功能.

以下是我迄今为止的代码,它显示了一个查询,该查询返回我需要下载 URL 链接的所有联系人 (URL_Fotograf_a_Cliente__c),但我没有比这更进一步的

from simple_salesforce import Salesforce, SFType, SalesforceLogin将熊猫导入为 pd导入json从 pprint 导入 pprint 作为 ppsession_id, instance = SalesforceLogin(username= username, password=password, security_token=security_token, sandbox=False)打印(会话 ID,实例)SF = Salesforce(实例= 实例,session_id=session_id)SOQL = "SELECT Id, Name,C_digo_del_Usuario__c,Tratamiento_IPA__c,Estado__c,Municipio__c,Comunidad__c, URL_Fotograf_a_Cliente__c FROM Contact WHERE Tratamiento_IPA__c IN ('x', 'y', 'z')pp(sf.query(query = SOQL))

解决方案

我一生中从未写过一行 Python 代码,但希望在这与 David 的回答之间你会有所收获.

图像是否已上传到 Salesforce?它们很可能在

所以你需要对它进行 base64 解码,重命名 &保存...

如果有东西被上传到文件,那么它的过程是相似的,只是不同的表.这篇博文看起来不错:https://crmcog.com/retrieve-sfdc-attachments-using-rest/

I have a csv of a series of contacts from Salesforce with the name, location and a URL that opens an image which I need to download

Thus far I have only been able to access my Salesforce instance using Python but am struggling to find a means of using a python package to not only open the URL, but also download the image in .jpg format and rename it with the name and location of the client.

Is there any package available that would allow my to do this. I've tried using simple-salesforce but I don't think it has this capability.

Below is the code i have so far showing a query that returns all the contacts that I need to download the URL link for (URL_Fotograf_a_Cliente__c), but I haven't got any further than that

from simple_salesforce import Salesforce, SFType, SalesforceLogin
import pandas as pd
import json
from pprint import pprint as pp

session_id, instance = SalesforceLogin(username= username, password=password, security_token=security_token, sandbox=False)

print(session_id,instance)

sf = Salesforce(instance= instance, session_id=session_id)

SOQL= "SELECT Id, Name,C_digo_del_Usuario__c,Tratamiento_IPA__c,Estado__c,Municipio__c,Comunidad__c, URL_Fotograf_a_Cliente__c FROM Contact WHERE Tratamiento_IPA__c IN ('x', 'y', 'z')"

pp(sf.query(query = SOQL))

解决方案

I've never written a line of Python code in my life but hopefully between this and David's answer you'll get somewhere.

Are the images uploaded to Salesforce? They're most likely in Attachment or File (ContentVersion) table. You could try to inspect the URL. All attachment record ids start with 00P.

I'mnot sure what your package uses, SOAP or REST API. In SOAP API you can get the body directly, as base64-encoded string. In REST API you can get a direct download URL.

SELECT Id, Name, Body, BodyLength, ContentType
FROM Attachment

So you'd base64-decode it, rename & save...

If something was uploaded to Files then it's similar process, just different table. This blog post looks like good start: https://crmcog.com/retrieve-sfdc-attachments-using-rest/

这篇关于使用 Python 从 Salesforce URL 下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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