function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Syam Mohan 13Syam 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
HarshHarsh (Salesforce Developers) 
Hi Syam,
Can you explain it a little more? If possible please attach the code and the screenshot.

Thasnks
Syam Mohan 13Syam Mohan 13
Hi Harsh,

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



 
gerald schefftersongerald scheffterson
Uploading large files from Salesforce to a Jira Case can sometimes feel like a daunting task, but there are a few tricks that can make the process smoother. Similar to how an xnxubd VPN browser (https://xnxubdvpnbrowser.online/) can enhance your online experience, using specialized integrations or third-party tools can help bridge the gap between Salesforce and Jira. These tools can enable you to batch-upload attachments or even compress files before sending, thereby bypassing size restrictions. So, before you find yourself stuck in a digital bottleneck, explore these options to ensure that your large files make it from Salesforce to Jira without a hitch.