I am getting the below error while uploading attachment for an incident in service now.
"error":{"detail":"Rejected large REST payload with content-length = 13011091 bytes. Max allowed: 10485760 bytes.","message":"Exception while reading request"},"status":"failure"}
Below is the code:
JSONObject AttachmentData = new JSONObject();
AttachmentData.put("agent", this.getAgent());
AttachmentData.put("topic", this.getTopic());
AttachmentData.put("name", this.getName());
AttachmentData.put("source", this.getSource());
AttachmentData.put("payload", this.getPayload());
try {
AuthenticationSNOWInfo auth = new AuthenticationSNOWInfo(sysDomain);
String UserId = auth.getUserId();
String Password = auth.getPassword();
if (this.webServiceAddress != null && !this.webServiceAddress.equalsIgnoreCase("")) {
logger.debug("Calling webservice: " + this.webServiceAddress);
snowLogger.debug("Calling webservice: " + this.webServiceAddress);
url = new URL(this.webServiceAddress);
conn = (HttpURLConnection) url.openConnection();
String encoded = java.util.Base64.getEncoder()
.encodeToString((UserId + ":" + Password).getBytes(StandardCharsets.UTF_8));
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Basic " + encoded);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
OutputStream os = conn.getOutputStream();
os.write(AttachmentData.toString().getBytes(StandardCharsets.UTF_8));
os.flush();
BufferedReader br;
logger.debug(conn.getResponseCode());
if (conn.getResponseCode() > 199 && conn.getResponseCode() < 300) {
br = new BufferedReader(new InputStreamReader((conn.getInputStream()),StandardCharsets.UTF_8));
} else {
br = new BufferedReader(new InputStreamReader((conn.getErrorStream()),StandardCharsets.UTF_8));
}
returnJSON = br.readLine();