【发布时间】:2017-11-30 09:50:56
【问题描述】:
背景
当我使用 Outlook 客户端发送带有内嵌图像的邮件时。
html邮件中的图片是这样的,有cid:
<img size="100" src="cid:3bb599fc-f3eb-465b-af83-aa6a495f563a" style="max-width:100%">
当我使用时
GET /me/messages/{messageId}/attachments
返回结果中的contentId与html中的cid相匹配。
{
"value": [
{
"@odata.type": "#microsoft.graph.fileAttachment",
"id": "aaa",
"lastModifiedDateTime": "2017-11-30T09:32:09Z",
"name": "image.png",
"contentType": "image/png",
"size": 100,
"isInline": true,
"contentId": "3bb599fc-f3eb-465b-af83-aa6a495f563a",
"contentLocation": null,
"contentBytes": "validBase64Bytes"
}
]
}
使用 Microsoft Graph API
现在我正在尝试使用 Microsoft Graph API 添加内联图像。
POST /me/messages/{messageId}/attachments
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "1.jpg",
"isInline": true,
"contentBytes": "validBase64Bytes"
}
但是,contentId 在返回的结果中为空。
{
"@odata.type": "#microsoft.graph.fileAttachment",
"id": "aaa",
"lastModifiedDateTime": "2017-11-30T09:35:50Z",
"name": "1.jpg",
"contentType": "image/jpeg",
"size": 100,
"isInline": true,
"contentId": null,
"contentLocation": null,
"contentBytes": "validBase64Bytes"
}
如果我在 POST 中手动设置 contentId
POST /me/messages/{messageId}/attachments
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "1.jpg",
"isInline": true,
"contentId": "myContentId",
"contentBytes": "validBase64Bytes"
}
它会返回错误
{
"error": {
"code": "BadRequest",
"message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.",
"innerError": {
"request-id": "36e95f0a-ad75-46c6-b86c-d585a150b96d",
"date": "2017-11-30T09:37:41"
}
}
}
那么如何正确添加内嵌图片呢?
【问题讨论】:
标签: json outlook microsoft-graph-api