【发布时间】:2020-10-12 05:19:33
【问题描述】:
我一直在尝试使用 JS force 为节点 js 下载图像文件,并能够在检索数据并将其转换为 base64 格式后在本地创建文件,但如果显示“文件不支持消息 " 同时能够下载具有正确数据的 javascript 类型的文件。
我在salesforce中查询知识文章的附件字段。
以下是我的查询:
SELECT Body__c, Attachment__Name__s, Attachment__ContentType__s, Attachment__Length__s, Attachment__Body__s, Id, KnowledgeArticleId, Title, UrlName FROM Knowledge__kav
我正在向文章的 Attachment__Body__s 字段发送 GET 请求。
以下是我的节点js代码:
function createFile(attachmentBody,attachmntContentType,attachmntName){
var req = {
url: attachmentBody,
method: 'GET',
headers: {
"Content-Type": attachmntContentType
}
};
var test = conn.request(req, function(err, resp) {
if (err) {
console.log(err)
} else {
var fileBuffer=Buffer.from(resp, 'binary').toString('base64');
console.log('fileBuffer--- '+ fileBuffer);
fs.writeFile('./downloadedAttachments/'+attachmntName,fileBuffer,'base64', function(err){
if (err) throw err
console.log('File saved.')
})
}
});
}
请帮帮我。
【问题讨论】:
标签: node.js rest salesforce workbench jsforce