uploadFile Method

uploadFile Method

Purpose

You can use this method to attach files to records.

Request URL

XML Format:
https://crm.zoho.com/crm/private/xml/Leads/uploadFile?authtoken=Auth Token&scope=crmapi&id=Record Id&content=File Input Stream

JSON Format:
https://crm.zoho.com/crm/private/json/Leads/uploadFile?authtoken=Auth Token&scope=crmapi&id=Record Id&content=File Input Stream

 Request Parameters

Parameter Data Type Description
authtoken* String Encrypted alphanumeric string to authenticate your Zoho credentials.
scope* String Specify the value as crmapi
id* String Specify unique ID of the "record" or "note" to which the file has to be attached.
content FileInputStream Pass the File Input Stream of the file
attachmentUrl String Attach 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 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 = "crmapi";
                  String targetURL = "https://crm.zoho.com/crm/private/xml/Leads/uploadFile";
                  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;
                  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();
            }
      }
}

Sample Response

<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/uploadFile">
      <result>
            <message>File has been attached successfully</message>
            <recorddetail>
                  <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>
            </recorddetail>
      </result>
</response>

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.
    • Related Articles

    • uploadFile Method - Comparison

      Purpose To attach a file to a record. Request URL Version 1.0: https://crm.zoho.com/crm/private/xml/Leads/uploadFile?authtoken=AuthToken&scope=crmapi&id=Record Id&content=File Input Stream Version 2.0: URL: ...
    • deleteRecords Method

      Table of Contents Purpose Request URL Request Parameters Example Purpose You can use this method to delete the selected record (you must specify unique ID of the record) and move to the recycle bin. Note: This method is availablefor all modules. ...
    • downloadPhoto Method

       Purpose You can use this method to download the photos of Leads or Contacts.  Request URL XML Format: For Leads: https://crm.zoho.com/crm/private/xml/Leads/downloadPhoto?authtoken=Auth Token&scope=crmapi&id=RecordID For Contacts: ...
    • searchRecords Method

       Purpose You can use the searchRecords method to get the list of records that meet your search criteria.  Request URL XML Format: https://crm.zoho.com/crm/private/xml/Leads/searchRecords?authtoken=Auth Token&scope=crmapi&criteria=(((Last ...
    • deleteFile Method

      Purpose You can use this method to delete files attached to records. Request URL XML Format: https://crm.zoho.com/crm/private/xml/Leads/deleteFile?authtoken=Auth Token&scope=crmapi&id=Attachment Id JSON Format: ...