uploadFile Method
Table of Contentsup
Purpose
You can use this method to attach files to records.
Request URL
XML Format:
https://<APPDOMAIN>/crm/private/xml/Leads/uploadFile?id=Record Id&content=File Input Stream
JSON Format:
https://<APPDOMAIN>/crm/private/json/Leads/uploadFile?id=Record Id&content=File Input Stream
Auth Token
Auth Token is an encrypted alphanumeric string that is required to authenticate your CRM account credentials. A valid user's Authentication Token is necessary to access the API. When making an API request, send the authentication token in the Authorization header as shown below:
https://<APPDOMAIN>/crm/private/xml/Leads/uploadFile?id=Record Id&content=File Input Stream
Header:
Authorization=1000XXXX65.1000XXXX44.caXXXXXXXXXXXX
(See Using Authentication Token )
Request Parameters
Parameter | Data Type | Description |
id* | String | Specify unique ID of the record to which the file has to be attached. |
content* | FileInputStream | Pass the File Input Stream of the file |
* - Mandatory parameter
Important Note:
- The total file size should not exceed 20 MB.
- Your program can request only 15 uploadFile calls per 5 min. If API User requests more than 15 calls, system will block the API access for 15 min.
- If the size exceeds 20 MB, you will receive the following error message: "File size should not exceed 20 MB".
- 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.
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://<APPDOMAIN>/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
- Default storage limits for the organization are:
- Free Edition - 256 MB for the Org.
- Professional Edition - 256 MB for each user license
- Enterprise Edition - 512 MB for each user license
- Extra file storage:USD 4/Month/GB
For the existing users, the revised pricing will be applicable from the next billing cycle.