uploadPhoto 方法
目的
您可以使用此方法上传照片至线索或联系人。
请求 URL
XML 格式:
线索:
https://crm.zoho.com.cn/crm/private/xml/Leads/uploadPhoto?authtoken=Auth Token&scope=crmapi&id=Record Id&content=File Input Stream
联系人:
https://crm.zoho.com.cn/crm/private/xml/Contacts/uploadPhoto?authtoken=Auth Token&scope=crmapi&id=Record Id&content=File Input Stream
请求参数
参数 | 数据类型 | 说明 |
authtoken* | 字符串 | 验证您的 Zoho 凭据的加密字母数字字符串。 |
scope* | 字符串 | 将数值指定为 crmapi |
id* | 字符串 | 指定记录的唯一 ID |
content* | FileInputStream | 通过照片的文档输入流 |
* - 必填参数
注意:
- 每张照片的大小不可超过 2 MB。 如果照片大小超过 2 MB,您将收到以下错误消息: “文档大小不得超过 2 MB”。
上传照片至线索或联系人的 Java 代码
您在您自己的 Java 环境中可以运行这一程序以便上传照片至线索或联系人。
在程序中,您需要为下列部分指定值:
- 您的验证令牌
- 记录 ID
- 上述格式的 uploadPhoto 请求 URL
- 文档路径即照片位置
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
public class UploadPhoto
public static void main(String args[])
{
try
{
String auth_token = "USER AUTH TOKEN";
String auth_scope = "crmapi";
String targetURL = "https://crm.zoho.com.cn/crm/private/xml/Leads/uploadPhoto";
String recordId = "RECORD ID";
String file = "FILE NAME";
File f = new File(file);
FileInputStream fis = new FileInputStream(f);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int c;
while ((c = fis.read()) != -1)
{
bos.write(c);
}
byte[] fbArray = bos.toByteArray();
if(useAuthToken)
{
targetURL = targetURL + "?authtoken="+ auth_token +"&scope="+ auth_scope;
}
PartSource ps = new ByteArrayPartSource(file,fbArray);
PostMethod post =new PostMethod(targetURL);
Part[] fields = { new FilePart("content",ps), new StringPart("id", recordId), };
post.setRequestEntity(new MultipartRequestEntity(fields,post.getParams()));
HttpClient httpclient = new HttpClient();
httpclient.executeMethod(post);
String postResp = post.getResponseBodyAsString();
System.out.println("postResp===========> : "+postResp);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
样本响应
<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/uploadPhoto">
<status>
<code>200</code>
</status>
<success>
<code>4800</code>
<message>Photo uploaded succuessfully</message>
</success>
</response>
上传照片至线索或联系人的 PHP 代码
<?php
$recordId="2000000016885";
$ch=curl_init();
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_VERBOSE,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_URL,"https://crm.zoho.com.cn/crm/private/xml/Leads/uploadPhoto?authtoken=<Your Authtoken>&scope=crmapi");
curl_setopt($ch,CURLOPT_POST,true);
$post=array("id"=>$recordId,"content"=>"@/home/path/to/my/photo.png");
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
$response=curl_exec($ch);
echo $response;
?>