System.StringException: Unrecognized base64 character:
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
1
down vote
favorite
I am trying to parse the response body which is in "base64 content of a file" and trying to create the attachment with the body but getting error of " Unrecognized base64 character: " I have included sample code of the response
"JVBERi0xLjQKJeLjz9MKNCAwIG9iaiA8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvTGVuZ3RoIDUzOTg+PnN0cmVhbQp4nM1dzXLbuLLe+ymwueWkyuGIFCVRs9M4mjk6Zcsex557qyZnQZOUzBRFyiCp69zHyJPMI3kZzuI8wwVIQKQ+AKIyk8WppKpBoPvrrxvNHxEk/Xz20/3ZgEymDrkPz+b3Z7+ePZ8NrMFwMiL/e+aQf7LBT2f2gFyf/f6vAQnPhmMyGY3J5mw0aVpJ3RqOrYHL2sODZjP+dPbfZynD4f/omjv84Web2J7FfNyvzux6wCbexHJHZDJ0uLjfnL25vFne383uyfs5YfK32eKKzMj7h7v5nHXdz++uF8v5/O39J07bBOo4U2s8JRN7YE28GvV+fn37gdzO7u4X8yth7TpkzNw7PC7bHVueLbeTdpuJEduudbttofd0tpIsPMs5ICHUxpOawJxFNSdX8w/kw83Dhw+LX5as+eNhHDqEiWu5NcCVT/IsiKuiIvPrJVlGRZF99tdRF8LRQoxHlt2QuIpIHn9dRzWSn5AoL1hHTt6RfpTRyJo2M7TYbPyCxkGZVBHxS3JnXVofLIZZ5iSJy.....
When i am trying to use this response body https://www.freeformatter.com/base64-encoder.html then i am able to download the pdf but getting error when trying to decode it from Sales force
Here is the code which i have written
List<Object> filesList = (List<Object>)responseMap.get('files');
Map<String, Object> files = (Map<String, Object>)filesList.get(0);
//String fileId = (String)files.get('id');
string fileId='92080882-cc3c-407d-9552-63ee02064733';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(youSignSetting[0].Base_URL__c+'/files/'+fileId+'/download');
request.setMethod('GET');
request.setheader('Content-Type', 'application/json; charset=UTF-8');
request.setHeader('Accept', 'application/json');
request.setHeader('Authorization','Bearer '+key);
request.setTimeOut(120000);
System.debug(' Procedure Creation '+request.getBody());
System.debug(' Procedure Creation '+request.getEndpoint());
System.debug(' Procedure Creation '+request.getHeader('Authorization'));
HttpResponse response1 = http.send(request);
if (response1.getStatusCode() == 200) {
String responseBody = response1.getbody();
//Encodingbody=EncodingUtil.base64Decode(responseBody);
string responsestring=responsebody.remove('"');
system.debug('Response body---->'+responseBody);
Attachment att = new Attachment();
att.ParentId = yp.ID_parent_attachment__c;
att.Name = yp.Name+' Attachment.pdf';
blob body=EncodingUtil.base64Decode(responsestring);
att.Body = body;
insert att;
}
else{
System.debug('The status code returned was not expected: ' +
response1.getStatusCode() + ' ' + response1.getStatus());
System.debug(response1.getBody());
}
}
}else{
System.debug('#### Start Procedure Error Message => '+response.ErrorMessage);
}
}
}
I have reviewed many articles regarding this but unable to get any result
apex httpresponse base64
add a comment |
up vote
1
down vote
favorite
I am trying to parse the response body which is in "base64 content of a file" and trying to create the attachment with the body but getting error of " Unrecognized base64 character: " I have included sample code of the response
"JVBERi0xLjQKJeLjz9MKNCAwIG9iaiA8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvTGVuZ3RoIDUzOTg+PnN0cmVhbQp4nM1dzXLbuLLe+ymwueWkyuGIFCVRs9M4mjk6Zcsex557qyZnQZOUzBRFyiCp69zHyJPMI3kZzuI8wwVIQKQ+AKIyk8WppKpBoPvrrxvNHxEk/Xz20/3ZgEymDrkPz+b3Z7+ePZ8NrMFwMiL/e+aQf7LBT2f2gFyf/f6vAQnPhmMyGY3J5mw0aVpJ3RqOrYHL2sODZjP+dPbfZynD4f/omjv84Web2J7FfNyvzux6wCbexHJHZDJ0uLjfnL25vFne383uyfs5YfK32eKKzMj7h7v5nHXdz++uF8v5/O39J07bBOo4U2s8JRN7YE28GvV+fn37gdzO7u4X8yth7TpkzNw7PC7bHVueLbeTdpuJEduudbttofd0tpIsPMs5ICHUxpOawJxFNSdX8w/kw83Dhw+LX5as+eNhHDqEiWu5NcCVT/IsiKuiIvPrJVlGRZF99tdRF8LRQoxHlt2QuIpIHn9dRzWSn5AoL1hHTt6RfpTRyJo2M7TYbPyCxkGZVBHxS3JnXVofLIZZ5iSJy.....
When i am trying to use this response body https://www.freeformatter.com/base64-encoder.html then i am able to download the pdf but getting error when trying to decode it from Sales force
Here is the code which i have written
List<Object> filesList = (List<Object>)responseMap.get('files');
Map<String, Object> files = (Map<String, Object>)filesList.get(0);
//String fileId = (String)files.get('id');
string fileId='92080882-cc3c-407d-9552-63ee02064733';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(youSignSetting[0].Base_URL__c+'/files/'+fileId+'/download');
request.setMethod('GET');
request.setheader('Content-Type', 'application/json; charset=UTF-8');
request.setHeader('Accept', 'application/json');
request.setHeader('Authorization','Bearer '+key);
request.setTimeOut(120000);
System.debug(' Procedure Creation '+request.getBody());
System.debug(' Procedure Creation '+request.getEndpoint());
System.debug(' Procedure Creation '+request.getHeader('Authorization'));
HttpResponse response1 = http.send(request);
if (response1.getStatusCode() == 200) {
String responseBody = response1.getbody();
//Encodingbody=EncodingUtil.base64Decode(responseBody);
string responsestring=responsebody.remove('"');
system.debug('Response body---->'+responseBody);
Attachment att = new Attachment();
att.ParentId = yp.ID_parent_attachment__c;
att.Name = yp.Name+' Attachment.pdf';
blob body=EncodingUtil.base64Decode(responsestring);
att.Body = body;
insert att;
}
else{
System.debug('The status code returned was not expected: ' +
response1.getStatusCode() + ' ' + response1.getStatus());
System.debug(response1.getBody());
}
}
}else{
System.debug('#### Start Procedure Error Message => '+response.ErrorMessage);
}
}
}
I have reviewed many articles regarding this but unable to get any result
apex httpresponse base64
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to parse the response body which is in "base64 content of a file" and trying to create the attachment with the body but getting error of " Unrecognized base64 character: " I have included sample code of the response
"JVBERi0xLjQKJeLjz9MKNCAwIG9iaiA8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvTGVuZ3RoIDUzOTg+PnN0cmVhbQp4nM1dzXLbuLLe+ymwueWkyuGIFCVRs9M4mjk6Zcsex557qyZnQZOUzBRFyiCp69zHyJPMI3kZzuI8wwVIQKQ+AKIyk8WppKpBoPvrrxvNHxEk/Xz20/3ZgEymDrkPz+b3Z7+ePZ8NrMFwMiL/e+aQf7LBT2f2gFyf/f6vAQnPhmMyGY3J5mw0aVpJ3RqOrYHL2sODZjP+dPbfZynD4f/omjv84Web2J7FfNyvzux6wCbexHJHZDJ0uLjfnL25vFne383uyfs5YfK32eKKzMj7h7v5nHXdz++uF8v5/O39J07bBOo4U2s8JRN7YE28GvV+fn37gdzO7u4X8yth7TpkzNw7PC7bHVueLbeTdpuJEduudbttofd0tpIsPMs5ICHUxpOawJxFNSdX8w/kw83Dhw+LX5as+eNhHDqEiWu5NcCVT/IsiKuiIvPrJVlGRZF99tdRF8LRQoxHlt2QuIpIHn9dRzWSn5AoL1hHTt6RfpTRyJo2M7TYbPyCxkGZVBHxS3JnXVofLIZZ5iSJy.....
When i am trying to use this response body https://www.freeformatter.com/base64-encoder.html then i am able to download the pdf but getting error when trying to decode it from Sales force
Here is the code which i have written
List<Object> filesList = (List<Object>)responseMap.get('files');
Map<String, Object> files = (Map<String, Object>)filesList.get(0);
//String fileId = (String)files.get('id');
string fileId='92080882-cc3c-407d-9552-63ee02064733';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(youSignSetting[0].Base_URL__c+'/files/'+fileId+'/download');
request.setMethod('GET');
request.setheader('Content-Type', 'application/json; charset=UTF-8');
request.setHeader('Accept', 'application/json');
request.setHeader('Authorization','Bearer '+key);
request.setTimeOut(120000);
System.debug(' Procedure Creation '+request.getBody());
System.debug(' Procedure Creation '+request.getEndpoint());
System.debug(' Procedure Creation '+request.getHeader('Authorization'));
HttpResponse response1 = http.send(request);
if (response1.getStatusCode() == 200) {
String responseBody = response1.getbody();
//Encodingbody=EncodingUtil.base64Decode(responseBody);
string responsestring=responsebody.remove('"');
system.debug('Response body---->'+responseBody);
Attachment att = new Attachment();
att.ParentId = yp.ID_parent_attachment__c;
att.Name = yp.Name+' Attachment.pdf';
blob body=EncodingUtil.base64Decode(responsestring);
att.Body = body;
insert att;
}
else{
System.debug('The status code returned was not expected: ' +
response1.getStatusCode() + ' ' + response1.getStatus());
System.debug(response1.getBody());
}
}
}else{
System.debug('#### Start Procedure Error Message => '+response.ErrorMessage);
}
}
}
I have reviewed many articles regarding this but unable to get any result
apex httpresponse base64
I am trying to parse the response body which is in "base64 content of a file" and trying to create the attachment with the body but getting error of " Unrecognized base64 character: " I have included sample code of the response
"JVBERi0xLjQKJeLjz9MKNCAwIG9iaiA8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvTGVuZ3RoIDUzOTg+PnN0cmVhbQp4nM1dzXLbuLLe+ymwueWkyuGIFCVRs9M4mjk6Zcsex557qyZnQZOUzBRFyiCp69zHyJPMI3kZzuI8wwVIQKQ+AKIyk8WppKpBoPvrrxvNHxEk/Xz20/3ZgEymDrkPz+b3Z7+ePZ8NrMFwMiL/e+aQf7LBT2f2gFyf/f6vAQnPhmMyGY3J5mw0aVpJ3RqOrYHL2sODZjP+dPbfZynD4f/omjv84Web2J7FfNyvzux6wCbexHJHZDJ0uLjfnL25vFne383uyfs5YfK32eKKzMj7h7v5nHXdz++uF8v5/O39J07bBOo4U2s8JRN7YE28GvV+fn37gdzO7u4X8yth7TpkzNw7PC7bHVueLbeTdpuJEduudbttofd0tpIsPMs5ICHUxpOawJxFNSdX8w/kw83Dhw+LX5as+eNhHDqEiWu5NcCVT/IsiKuiIvPrJVlGRZF99tdRF8LRQoxHlt2QuIpIHn9dRzWSn5AoL1hHTt6RfpTRyJo2M7TYbPyCxkGZVBHxS3JnXVofLIZZ5iSJy.....
When i am trying to use this response body https://www.freeformatter.com/base64-encoder.html then i am able to download the pdf but getting error when trying to decode it from Sales force
Here is the code which i have written
List<Object> filesList = (List<Object>)responseMap.get('files');
Map<String, Object> files = (Map<String, Object>)filesList.get(0);
//String fileId = (String)files.get('id');
string fileId='92080882-cc3c-407d-9552-63ee02064733';
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(youSignSetting[0].Base_URL__c+'/files/'+fileId+'/download');
request.setMethod('GET');
request.setheader('Content-Type', 'application/json; charset=UTF-8');
request.setHeader('Accept', 'application/json');
request.setHeader('Authorization','Bearer '+key);
request.setTimeOut(120000);
System.debug(' Procedure Creation '+request.getBody());
System.debug(' Procedure Creation '+request.getEndpoint());
System.debug(' Procedure Creation '+request.getHeader('Authorization'));
HttpResponse response1 = http.send(request);
if (response1.getStatusCode() == 200) {
String responseBody = response1.getbody();
//Encodingbody=EncodingUtil.base64Decode(responseBody);
string responsestring=responsebody.remove('"');
system.debug('Response body---->'+responseBody);
Attachment att = new Attachment();
att.ParentId = yp.ID_parent_attachment__c;
att.Name = yp.Name+' Attachment.pdf';
blob body=EncodingUtil.base64Decode(responsestring);
att.Body = body;
insert att;
}
else{
System.debug('The status code returned was not expected: ' +
response1.getStatusCode() + ' ' + response1.getStatus());
System.debug(response1.getBody());
}
}
}else{
System.debug('#### Start Procedure Error Message => '+response.ErrorMessage);
}
}
}
I have reviewed many articles regarding this but unable to get any result
apex httpresponse base64
apex httpresponse base64
asked Nov 27 at 16:43
Avesh
255
255
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
The content you are receiving is not Base64: it is Base64 inside JSON, which you are asking the server to provide to you. Base64 encoding uses the characters [A-Za-z0-9+/]
. The backslash and quote characters shown here are not part of the Base64 encoding but the JSON wrapper around it.
You need to deserialize the JSON first, into a String
, and then Base64-decode that String:
String base64Content = JSON.deserialize(response1.getBody(), String.class));
Blob body = EncodingUtil.base64Decode(base64Content);
Thanks @David It worked
– Avesh
Nov 27 at 17:12
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
The content you are receiving is not Base64: it is Base64 inside JSON, which you are asking the server to provide to you. Base64 encoding uses the characters [A-Za-z0-9+/]
. The backslash and quote characters shown here are not part of the Base64 encoding but the JSON wrapper around it.
You need to deserialize the JSON first, into a String
, and then Base64-decode that String:
String base64Content = JSON.deserialize(response1.getBody(), String.class));
Blob body = EncodingUtil.base64Decode(base64Content);
Thanks @David It worked
– Avesh
Nov 27 at 17:12
add a comment |
up vote
5
down vote
accepted
The content you are receiving is not Base64: it is Base64 inside JSON, which you are asking the server to provide to you. Base64 encoding uses the characters [A-Za-z0-9+/]
. The backslash and quote characters shown here are not part of the Base64 encoding but the JSON wrapper around it.
You need to deserialize the JSON first, into a String
, and then Base64-decode that String:
String base64Content = JSON.deserialize(response1.getBody(), String.class));
Blob body = EncodingUtil.base64Decode(base64Content);
Thanks @David It worked
– Avesh
Nov 27 at 17:12
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
The content you are receiving is not Base64: it is Base64 inside JSON, which you are asking the server to provide to you. Base64 encoding uses the characters [A-Za-z0-9+/]
. The backslash and quote characters shown here are not part of the Base64 encoding but the JSON wrapper around it.
You need to deserialize the JSON first, into a String
, and then Base64-decode that String:
String base64Content = JSON.deserialize(response1.getBody(), String.class));
Blob body = EncodingUtil.base64Decode(base64Content);
The content you are receiving is not Base64: it is Base64 inside JSON, which you are asking the server to provide to you. Base64 encoding uses the characters [A-Za-z0-9+/]
. The backslash and quote characters shown here are not part of the Base64 encoding but the JSON wrapper around it.
You need to deserialize the JSON first, into a String
, and then Base64-decode that String:
String base64Content = JSON.deserialize(response1.getBody(), String.class));
Blob body = EncodingUtil.base64Decode(base64Content);
answered Nov 27 at 16:52
David Reed
26.7k51745
26.7k51745
Thanks @David It worked
– Avesh
Nov 27 at 17:12
add a comment |
Thanks @David It worked
– Avesh
Nov 27 at 17:12
Thanks @David It worked
– Avesh
Nov 27 at 17:12
Thanks @David It worked
– Avesh
Nov 27 at 17:12
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f240678%2fsystem-stringexception-unrecognized-base64-character%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown