You need to sign in to do that
Don't have an account?
Syam Mohan 13
How to upload files of large size as attachment from Salesforce to Jira Case
While trying to upload Case Post attachments from Salesforce to Jira, the functionality works fine for documents of size < 6MB. But while trying with files of 50 MB it is showing one error "string length exceeds maximum: 12000000".
Could please let me know if there any alternative way to accomplish large file deployment from Salesforce to Jira?
Thanks,
Syam
Could please let me know if there any alternative way to accomplish large file deployment from Salesforce to Jira?
Thanks,
Syam
Can you explain it a little more? If possible please attach the code and the screenshot.
Thasnks
I am trying to upload case attachments to Jira from Salesforce. I am able to upload attachments to Jira Case with the the below callout apex code which is running in Batch Apex.
And the code is working fine for documents of size < 6MB. But when i am trying to upload attachments of larger size ( > 50 MB), i am getting the error like "string length exceeds maximum: 12000000". Is there any way to accomplish the upload of larger size case attachments to Jira?
Apex Code:
String bodyEncoded;
String boundary = '----------------------------741e90d31eff';
String file_name = <CONTENT_VERSION.PATH_ON_CLIENT>;
String header = '--' + boundary + '\n' +'Content-Disposition: form-data; name="file"; filename="' + file_name + '";\n'+'Content-Type: application/octet-stream';
String footer = '--' + boundary + '--';
String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header + '\r\n\r\n'));
while (headerEncoded.endsWith('=')){
header += ' ';
headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\r\n\r\n'));
}
Blob versionDataBlob = contentVer.VersionData;
bodyEncoded = EncodingUtil.base64Encode(versionDataBlob);
System.debug('bodyEncoded : '+bodyEncoded);
Blob bodyBlob = null;
String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length());
if (last4Bytes.endsWith('==')) {
last4Bytes = last4Bytes.substring(0, 2) + '0K';
bodyEncoded = bodyEncoded.substring(0, bodyEncoded.length() - 4) + last4Bytes;
String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
bodyBlob = EncodingUtil.base64Decode(headerEncoded + bodyEncoded + footerEncoded);
} else if (last4Bytes.endsWith('=')) {
last4Bytes = last4Bytes.substring(0, 3) + 'N';
bodyEncoded = bodyEncoded.substring(0, bodyEncoded.length()-4) + last4Bytes;
footer = '\n' + footer;
String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
bodyBlob = EncodingUtil.base64Decode(headerEncoded + bodyEncoded + footerEncoded);
} else {
footer = '\r\n' + footer;
String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
bodyBlob = EncodingUtil.base64Decode(headerEncoded + bodyEncoded + footerEncoded);
}
System.debug('bodyBlob : '+bodyBlob);
String endpoint = jiraURL+'/rest/api/2/issue/'+caseJiraIssueKey+'/attachments';
HttpRequest request = new HttpRequest();
HttpResponse response = new HttpResponse();
Http http = new Http();
String authorizationHeader = 'Bearer ' + Password;
request.setHeader('Authorization', authorizationHeader);
request.setHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
request.setHeader('X-Atlassian-Token', 'nocheck');
request.setMethod('POST');
//request.setBody('{"body": '+caseCommentBody+'}');
request.setBodyAsBlob(bodyBlob);
request.setTimeout(120000);
request.setEndpoint(endpoint);
response = http.send(request);
Thanks,
Syam