Hi Shital,
Thanks Awais,
I have attached the Docx file which resides on the Aspose cloud server and the converted Pdf file which is received from calling the api http://api.aspose.com/v1.1/words/SignInSheetDataSource_Sample-Merged.docx?format=Pdf&appSID=45935a38-ef19-47d8-a5b9-d564c95c6d76&signature=RKftTgIoSvDWZY4DNU9DO8j11FE.
When we copy paste the above url in the browser it displays the correct pdf and can be save/downloaded from browser and works fine.
We are facing problem when calling this api from the code at Salesforce cloud plateform and extracting the blob from the response and save to the Attachment object. Then when I want to see the PDF from the Attachment object, it does not loads the content.
Following is the code snippet in Salesforce plateform :
To Download PDF file :
String fileName = ‘SignInSheetDataSource_Sample-Merged.docx’;
String strURI = Aspose.BaseProductUri + ‘/words/’ + fileName + ‘?format=Pdf’;
String signedURI = AsposeUtils.Sign(strURI);
system.debug(‘strURI===> ‘+strURI);
Blob fileContent= AsposeUtils.ProcessCommand(signedURI, ‘GET’, ‘json’)
//Create the Attachment object :
Attachment att = new Attachment();
att.Body = mergedFileBlob;
att.ParentId = doc.Id;
att.ContentType = ‘pdf’;
att.Name = fileName;
insert att;
//Definition of ProcessCommand method
public static Blob ProcessCommand(String strURI, String strHttpCommand, String ContentType) {
try {
HttpRequest request = new HttpRequest();
Integer len = 0;
request.setEndpoint(strURI);
request.setMethod(strHttpCommand);
if (ContentType.toLowerCase() == ‘xml’){
request.setHeader(‘Content-Type’, ‘application/xml’);
}else if (ContentType.toLowerCase() == ‘json’){
request.setHeader(‘Content-Type’, ‘application/json’);
}else{
request.setHeader(‘Content-Type’, ‘MultiPart/Form-Data’);
}
request.setHeader(‘Content-Length’, String.valueOf(len));
request.setHeader(‘Accept’, ‘application/json’);
request.setTimeout(99999);
if(TEST.isRunningTest() ){
return Blob.valueOf(‘This is for Test’);
} else{
Http http = new Http();
HttpResponse res = http.send(request);
system.debug(’### Download file res :’+res.getBody());
return res.getBodyAsBlob();
}
} catch (Exception ex) {
system.debug(‘HTTP ERROR’ + ex.getMessage());
throw new DataSourceException('ASPOSE Service Exception : '+ex);
return null;
}
}
Hi Shital,