You need to sign in to do that
Don't have an account?
Prateek Bhatt
Conver RTA image into base64 encode
I am not able to convert the rtaimage URL into the base64 encoding URL. Please have a look into below code and provide me the help on below issue.
HttpRequest req = new HttpRequest();
String url = system.URL.getSalesforceBaseUrl().toExternalForm() + '/secur/frontdoor.jsp?sessionId=' + UserInfo.getSessionId() + '&retURL="/servlet/rtaImage?eid=5007000000uEmHK&feoid=00N70000002UTY9&refid=0EMc0000000DDdk"';
req.setEndpoint(url);
req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
req.setMethod('GET');
Http binding = new Http();
HttpResponse res = binding.send(req);
Blob image = res.getBodyAsBlob();
String base64Encode = EncodingUtil.base64Encode(image);
String caseDescription = '<img alt="" src="data:' + res.getHeader('Content-Type') + ';' + base64Encode + '"></img>';
CaseDescRichTextStage__c stgObj = new CaseDescRichTextStage__c(CaseNumber__c = 'C-121', CaseDescBase64__c = caseDescription);
I am getting the below error while save this record with base64Encode URL.
Invalid data specified, the provided data does not seem to be a valid image: [B@254f39ef
I have also checked the value of res.getHeader('Content-Type'). It's giving me "text/html;charset=UTF-8" instead of 'image/png'
HttpRequest req = new HttpRequest();
String url = system.URL.getSalesforceBaseUrl().toExternalForm() + '/secur/frontdoor.jsp?sessionId=' + UserInfo.getSessionId() + '&retURL="/servlet/rtaImage?eid=5007000000uEmHK&feoid=00N70000002UTY9&refid=0EMc0000000DDdk"';
req.setEndpoint(url);
req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
req.setMethod('GET');
Http binding = new Http();
HttpResponse res = binding.send(req);
Blob image = res.getBodyAsBlob();
String base64Encode = EncodingUtil.base64Encode(image);
String caseDescription = '<img alt="" src="data:' + res.getHeader('Content-Type') + ';' + base64Encode + '"></img>';
CaseDescRichTextStage__c stgObj = new CaseDescRichTextStage__c(CaseNumber__c = 'C-121', CaseDescBase64__c = caseDescription);
I am getting the below error while save this record with base64Encode URL.
Invalid data specified, the provided data does not seem to be a valid image: [B@254f39ef
I have also checked the value of res.getHeader('Content-Type'). It's giving me "text/html;charset=UTF-8" instead of 'image/png'
I am also trying to encode image(jpg) into base64 format.I want to send that image to external system.
code:-
if(Image2 != NULL)
{
Blob b=Blob.valueof(Image2);
req1.setBodyAsBlob(b);
fileString=EncodingUtil.Base64Encode(b);
System.debug('is now encoded as:'+fileString);
}
String domainName1='52.6.251.159/~democrm/demo/vtigerdefault/services/rest/rest.php?';
String endPointURL1='http://'+domainName1+'api_key=asws29qw3r545ndm&method=uploadImage&&image_name='+Image1+'&salesforce_id='+name3+'&image='+fileString;
System.debug('>>>>>>>>>>>>>>>>>'+endPointURL1);
req1.setEndpoint(endPointURL1);
req1.setMethod('POST');
req1.setCompressed(true);
For converting image to base64 ,is this code is wrong..?