• Raja Pragallapati
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I am trying to get the data PDF file from REST API, while storing it into the attachment object as PDF it is showing the empty PDF pages, kidnly help me to solve this issue. 

Note:- Encodeutil decode and encode not wokring while attachment creating converting the response,getBody() into attachment. 
 
string url = AWSUtility.viewS3Object('a1h0n00000187sc');
system.debug('The url is:' + url);

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(url);
request.setMethod('GET');
request.setHeader('Content-Type', 'application/pdf'); 
request.setHeader('Content-Encoding', 'UTF-8');
//req.setHeader('Content-Disposition', 'attachment; filename=' + fileName);
//req.setHeader('Connection', 'keep-alive');

HttpResponse response = http.send(request);
system.debug('The response is :' +response.getBody());
attachment att = new attachment();
att.parentId = 'a1h2g000000I1IN';
att.Name = 'Testing Raja2.pdf';
att.contentType = 'application/pdf'; 

att.body = blob.valueof(response.getBody());

//att.body = EncodingUtil.Base64Decode(response.getBody());
//att.body = EncodingUtil.base64Decode(response.getBody());
//att.body = EncodingUtil.base64Decode(blob.valueof(response.getBody()));
//att.body = EncodingUtil.base64Encode(blob.valueof(response.getBody()));
insert att;  (// attachment is getting created but, all empty pages only).