Recruit 帮助

uploadPhoto 方法

  1. 目的
  2. 请求 URL
  3. 请求参数
  4. 为应聘者或联系人上传图片的 Java 代码
  5. 示例响应
  6. 上传图片的 PHP 代码
     

目的

您可以使用此方法为应聘者联系人上传图片。

请求 URL

XML 格式:

对于应聘者:
https://recruit.zoho.com.cn/recruit/private/xml/Candidates/uploadPhoto?authtoken=Auth Token&scope=recruitapi&id=Record Id&content=File Input Stream&version=2

对于联系人:
https://recruit.zoho.com.cn/recruit/private/xml/Contacts/uploadPhoto?authtoken=Auth Token&scope=recruitapi&id=Record Id&content=File Input Stream&version=2

请求参数

参数 数据类型 描述
authtoken* 字符串 加密的字母数字字符串,用来对 Zoho 凭证进行身份验证。
scope* 字符串 将值指定为 recruitapi
id* 字符串 指定记录的唯一 ID。
content* FileInputStream 传递图片的 FileInputStream。
version* 整数 使用version=2:这将基于最新 API 实施来提取响应。

* - 必备参数

备注:每张图片的大小不能超过 2 MB。如果大小超过 2 MB,您将收到以下错误消息:“文件大小不得超过 2 MB。”

为应聘者或联系人上传图片的 Java 代码

您可以在 Java 环境运行此程序以上传应聘者或联系人的图片。

在程序中,您需要指定以下值:

  1. 您的身份验证令牌
  2. 记录的 ID
  3. 上面提到的格式中的 uploadPhoto 请求 URL
  4. 文件路径,即图片的位置

 

import java.io.*;
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 UploadFile 
{
public static void main(String a[])
{
try
{
String auth_token = "USER AUTH TOKEN"; 
String auth_scope = "recruitapi";
String targetURL = "https://recruit.zoho.com.cn/recruit/private/xml/Candidates/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();
targetURL = targetURL + "?authtoken="+ auth_token +"&scope="+ auth_scope+"&version=2";
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="/recruit/private/xml/Candidates/uploadPhoto">
<status>
<code>200</code>
</status>
<success>
<code>4800</code>
<message>Photo uploaded successfully</message>
</success>
</response>

为应聘者或联系人上传图片的 PHP 代码(适用于 PHP 5.5 或更高版本)

<?php
$recordId="RECORD ID";
$ch=curl_init();
$cFile = new CURLFile('/home/path/to/my/photo.png','image/png',")

curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_VERBOSE,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_URL,"https://recruit.zoho.com.cn/recruit/private/xml/Candidates/uploadPhoto?authtoken=<Your Authtoken>&scope=recruitapi&version=2");
curl_setopt($ch,CURLOPT_POST,true);
$post=array("id"=>$recordId,"content"=>$cFile);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
$response=curl_exec($ch);
echo $response;
?>

还是没有找到您要寻找的内容?

写信给我们:support@zohocorp.com.cn