Salesforce附件经Outlook发送后非文本文件格式损坏问题求助
问题根源与解决方案
问题出在重复Base64编码:Salesforce返回的Attachment.Body本身就是Base64格式的二进制内容,你现在的代码把它转成Binary后又调用toBase64,等于对原始内容做了两次Base64编码,非文本文件(如Excel)对编码错误容错性低,所以会出现文件损坏、格式不匹配的问题。
修正后的DataWeave代码
import * from dw::core::Binaries output application/json var subject = "This is a test" var attachments = vars.varAttachmentArray map ((item, index) -> { "@odata.type": "#microsoft.graph.fileAttachment", name: item.filename[0], contentType: item.contentType[0], // 直接使用Salesforce返回的原始Base64值,无需二次编码 contentBytes: item.content[0] }) --- { "message": { "subject": subject, "body": { "contentType": "HTML", "content": "Test" }, "toRecipients": [{ "emailAddress": { "address": "test@myorg.com" } }], "ccRecipients": [], "attachments": attachments }, "saveToSentItems": "false" }
额外注意事项
- 确认
item.content[0]确实对应Salesforce Attachment的Body字段:如果变量映射时把Body存到了其他字段,要替换成正确的字段名。 - 检查文件名与ContentType的一致性:比如Excel文件如果是.xlsx后缀,ContentType要对应
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,避免系统因后缀和类型不匹配弹出警告(即使文件本身没问题)。
内容的提问来源于stack exchange,提问作者Triumph Spitfire
相关产品推荐
相关产品推荐

