CRM Help

uploadFile Method


You can use this method to attach files to records.

Request URL

XML Format: Token&scope=crmapi&id=Record Id&content=File Input Stream

JSON Format: Token&scope=crmapi&id=Record Id&content=File Input Stream

 Request Parameters

ParameterData TypeDescription
authtoken*StringEncrypted alphanumeric string to authenticate your Zoho credentials.
scope*StringSpecify the value as crmapi
id*StringSpecify unique ID of the "record" or "note" to which the file has to be attached.
contentFileInputStreamPass the File Input Stream of the file
attachmentUrlStringAttach a URL to a record.

* - Mandatory parameter

Important Note:

  • The total file size should not exceed 20 MB.
  • Your program can request only up to 60 uploadFile calls per min. If API User requests more than 60 calls, system will block the API access for 5 min. 
  • If the size exceeds 20 MB, you will receive the following error message: "File size should not exceed 20 MB". This limit does not apply to URLs attached via attachmentUrl.
  • The attached file will be available under the Attachments section in the Record Details Page.
  • Files can be attached to records in all modules except Reports, Dashboards and Forecasts.
  • In the case of the parameter attachmentUrl, content is not required as the attachment is from a URL.
    Example for attachmentUrl: crm/private/xml/Leads/uploadFile?authtoken=*****&scope=crmapi&id=<entity_id>&attachmentUrl=<insert_ URL>

Java Code to Upload a file to a record

You can run this program in your Java Environment to upload a file to a record.

In the program, you need to specify values for the following:
  • Your Auth Token
  • The ID of the Record
  • The uploadFile Request URL in the format mentioned above
  • The File Path i.e the location of the File

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[])
                  String auth_token = "USER AUTH TOKEN"; 
                  String auth_scope = "crmapi";
                  String targetURL = "";
                  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 = != -1)
                  byte[] fbArray = bos.toByteArray();
                  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();
                  String postResp = post.getResponseBodyAsString();
                  System.out.println("postResp===========> : "+postResp);
            catch(Exception e)

Sample Response

<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/uploadFile">
            <message>File has been attached successfully</message>
                  <FL val="Id">335751000000578001</FL>
                  <FL val="Created Time">2012-06-20 14:57:34</FL>
                  <FL val="Modified Time">2012-06-20 14:57:34</FL>
                  <FL val="Created By"><![CDATA[krrish]]></FL>
                  <FL val="Modified By"><![CDATA[krrish]]></FL>

Data Storage Limits

The default free storage available in the Free Edition is 1 GB per Org account. In addition to this free 1 GB, the following are the Data Storage limits in each paid edition, applicable per user.

  • Professional Edition - 512 MB per user license
  • Standard Edition - 512 MB per user license
  • Enterprise Edition - 1 GB per user license
  • CRM Plus - 1 GB per user license
  • Extra file storage: USD 4/Month/ 5 GB
    For the existing users, the revised pricing will be applicable from the next billing cycle.

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: