Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String boundary = '-741d90e31frt';
- String header = '--'+boundary+'nContent-Disposition: form-data; name="pdfFile"; filename="'+Pdf_id+'.pdf";nContent-Type: application/octet-stream';
- String footer = '--'+boundary+'--';
- String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'rnrn'));
- String bodyEncoded = EncodingUtil.base64Encode(pdf_Body);
- while(headerEncoded.endsWith('=')){
- header+=' ';
- headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'rnrn'));
- }
- 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+headerEncoded1+bodyEncoded1+footerEncoded1);
- }
- 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+headerEncoded1+bodyEncoded1+footerEncoded1);
- }
- else if(last4Bytes.endsWith('9G')){
- system.debug('Entered in 9G');
- bodyEncoded = bodyEncoded +'Cg0K';
- String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
- // bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+headerEncoded1+bodyEncoded1+footerEncoded1);
- }
- else {
- footer = 'rn' + footer;
- String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
- // bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+headerEncoded1+bodyEncoded1+footerEncoded1);
- }
- String header1 = '--'+boundary+'nContent-Disposition: form-data; name="signFile"; filename="'+image_id+'";nContent-Type: application/octet-stream'; //octet-stream
- String footer1 = '--'+boundary+'--';
- String headerEncoded1 = EncodingUtil.base64Encode(Blob.valueOf(header1+'rnrn'));
- while(headerEncoded1.endsWith('=')){
- header1+=' ';
- headerEncoded1 = EncodingUtil.base64Encode(Blob.valueOf(header1+'rnrn'));
- }
- String bodyEncoded1 = EncodingUtil.base64Encode(image_Body);
- String last4Bytes1 = bodyEncoded1.substring(bodyEncoded1.length()-4,bodyEncoded1.length());
- if(last4Bytes1.endsWith('==')) {
- last4Bytes1 = last4Bytes1.substring(0,2) + '0K';
- bodyEncoded1 = bodyEncoded1.substring(0,bodyEncoded1.length()-4) + last4Bytes1;
- String footerEncoded1 = EncodingUtil.base64Encode(Blob.valueOf(footer1));
- // bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+headerEncoded1+bodyEncoded1+footerEncoded1);
- }
- else if(last4Bytes1.endsWith('=')) {
- last4Bytes1 = last4Bytes1.substring(0,3) + 'N';
- bodyEncoded1 = bodyEncoded1.substring(0,bodyEncoded1.length()-4) + last4Bytes1;
- footer1 = 'n' + footer1;
- String footerEncoded1 = EncodingUtil.base64Encode(Blob.valueOf(footer1));
- //bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+headerEncoded1+bodyEncoded1+footerEncoded1);
- }
- else if(last4Bytes1.endsWith('9G')){
- system.debug('Entered in 9G');
- bodyEncoded1 = bodyEncoded1 +'Cg0K';
- String footerEncoded1 = EncodingUtil.base64Encode(Blob.valueOf(footer1));
- // bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+headerEncoded1+bodyEncoded1+footerEncoded1);
- }
- else {
- footer1 = 'rn' + footer1;
- String footerEncoded1 = EncodingUtil.base64Encode(Blob.valueOf(footer1));
- // bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+headerEncoded1+bodyEncoded1+footerEncoded1);
- }
- String footerEncoded1 = EncodingUtil.base64Encode(Blob.valueOf(footer1));
- bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+headerEncoded1+bodyEncoded1+footerEncoded1);
- HttpRequest requ = new HttpRequest();
- requ.setHeader('Content-Type','multipart/form-data; boundary='+boundary);
- requ.setMethod('POST');
- requ.setEndpoint(pointer.endpoint_url__c+'/xxxxxxx/XXXXX/XXX/XX');
- String username = 'XXXXXX';
- String password = 'XXXXXX';
- Blob headerValue = Blob.valueOf(username + ':' + password);
- String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
- requ.setHeader('Authorization', authorizationHeader);
- requ.setBodyAsBlob(bodyBlob);
- requ.setTimeout(120000);
- Http http = new Http();
- HTTPResponse res = http.send(requ);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement