seanlin
07/20/2020, 9:20 AMfunction getPdf2(context){
const pdfFileUrl = '<https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf>';
const header = {
'Accept': 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8, application/xxx',
'Accept-Language': 'en-us'
}
let pdfResponse = https.get(pdfFileUrl, header);
log.debug({title: 'getPdf2 response header', details: JSON.stringify(pdfResponse.headers)});
log.debug({title: 'getPdf2 response body', details: pdfResponse.body});
log.debug({title: 'getPdf2 response content-length', details: pdfResponse.headers['Content-Length']});
const pdfFile2 = file.create({
name: 'dummy.pdf',
fileType: file.Type.PDF,
contents: encode.convert({
string: pdfResponse.body,
inputEncoding: encode.Encoding.UTF_8,
outputEncoding: encode.Encoding.BASE_64
})
});
context.response.writeFile({file: pdfFile2, isInline: true});
}
what I am trying to achieve is to get pdf from another url and display the file content in the suitelet. The result shows empty file content. It appears that I am doing something wrong in the encode.convert section. Does anyone have experience with it?Kyriakos Zisopoulos
07/20/2020, 12:08 PMseanlin
07/20/2020, 1:03 PMbattk
07/20/2020, 1:29 PMbattk
07/20/2020, 1:29 PMbattk
07/20/2020, 1:32 PMapplication/pdf
battk
07/20/2020, 1:34 PMapplication/pdf
should make the body base64, which you can save directly into the file cabinetseanlin
07/20/2020, 3:48 PMbattk
07/20/2020, 7:28 PMbattk
07/20/2020, 7:29 PMseanlin
07/20/2020, 11:42 PMbattk
07/20/2020, 11:48 PMbattk
07/20/2020, 11:49 PM