setBinaryData
Purpose
Sets the binary data (file attachment) associated with a particular file field from a specific record.
HTTP Method
GET
or POST
URL
https://app.infiniteblue.com/rest/api/setBinaryData
URL Parameters
id
Record's id.
fieldName
The field integration name.
value
Value to be set. Must be formatted the same way as values in spreadsheet imports. For File Upload fields: Base-64 encoded binary value of file.
contentType
For File Upload fields only: MIME content type of uploaded data .
fileName
For File Upload fields only: original name of file being uploaded.
output
Optional parameter specifying the output format, one of:
sessionId
The session ID obtained from the body of the response when calling login.
Permissions Required
Edit permission for the requested object type.
Response
Status message wrapped in XML
Example
The following example uploads documents.
import java.io.File; import java.io.FileInputStream; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; import org.apache.commons.httpclient.methods.multipart.Part; import org.apache.commons.httpclient.methods.multipart.StringPart; public class TestSetBinaryData { public static void main(String[] args) { // Apache HTTP client 3.1 PostMethod post = new PostMethod(); HttpClient httpclient = new HttpClient(); String postResponse = null; try { post = new PostMethod( "https://app.infiniteblue.com/rest/api/ setBinaryData?sessionId=0bb05ac9c5074ebb9d3d460cc7f48696@2722356"); // Multi-part upload Part[] p1 = new Part[6]; p1[0] = new StringPart("id", "97062227"); // record id p1[1] = new StringPart("objName", "Object1"); // object integration name p1[2] = new StringPart("fieldName", "Field1"); // field integration name p1[3] = new StringPart("contentType", "application/pdf"); // file content type p1[4] = new StringPart("fileName", "abc.pdf"); // file name File f = new File("C:\\BinaryFileTest\\abc.pdf"); // actual file FileInputStream fileInputStream = null; byte[] bFile = new byte[(int) f.length()]; try { fileInputStream = new FileInputStream(f); fileInputStream.read(bFile); fileInputStream.close(); } catch (Exception e) { e.printStackTrace(); } String encodeBase64Str = Base64.encodeBase64String(bFile); // Convert to Base64 encoded format System.out.println("length is " + encodeBase64Str.length()); p1[5] = new StringPart("value", encodeBase64Str); post.setRequestEntity(new MultipartRequestEntity(p1, post.getParams())); httpclient.executeMethod(post); postResponse = post.getResponseBodyAsString(); System.out.println("Response is" + postResponse); } catch (Exception e) { e.printStackTrace(); } finally { post.releaseConnection(); } } }