Skip to content

Instantly share code, notes, and snippets.

@muehlburger
Created March 16, 2016 07:04
Show Gist options
  • Save muehlburger/f87e7937ee8a3df39e77 to your computer and use it in GitHub Desktop.
Save muehlburger/f87e7937ee8a3df39e77 to your computer and use it in GitHub Desktop.
public String createAttachment(String caseId, String path, String filename) throws Exception {
Path file = Paths.get(path);
byte[] data = Files.readAllBytes(file);
JSONObject obj = new JSONObject();
obj.put("ParentId", caseId);
obj.put("Name", filename);
obj.put("body", new String(Base64.encodeBase64(data)));
List<JSONObject> response = doPost("Attachment", obj.toString());
String documentId = "";
if(response.size() > 0) {
JSONObject result = response.get(0);
if(result.getBoolean("success")) {
documentId = (String) result.getString("id");
}
}
return documentId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment