[英]How to add inline image by Microsoft Graph API?
When I use Outlook client to send a mail with inline image.当我使用 Outlook 客户端发送带有内嵌图像的邮件时。
The image in html email looks like this, which has cid : html 电子邮件中的图像如下所示,其中包含cid :
<img size="100" src="cid:3bb599fc-f3eb-465b-af83-aa6a495f563a" style="max-width:100%">
When I use当我使用
GET /me/messages/{messageId}/attachments
The contentId in the result returned matched the cid in html.返回结果中的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"
}
]
}
Now I am trying to use Microsoft Graph API to add inline image.现在我正在尝试使用 Microsoft Graph API 添加内嵌图像。
POST /me/messages/{messageId}/attachments
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "1.jpg",
"isInline": true,
"contentBytes": "validBase64Bytes"
}
However, the contentId
is null in the result returned.但是,返回的结果中的contentId
为 null。
{
"@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"
}
And if I set contentId
manually in POST如果我在 POST 中手动设置contentId
POST /me/messages/{messageId}/attachments
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "1.jpg",
"isInline": true,
"contentId": "myContentId",
"contentBytes": "validBase64Bytes"
}
It will return the error它会返回错误
{
"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"
}
}
}
So how to add inline image correctly?那么如何正确添加内嵌图片呢?
Weird, I tried to run the exact same code again, it won't give me any error now.奇怪的是,我再次尝试运行完全相同的代码,它现在不会给我任何错误。
POST /me/messages/{messageId}/attachments
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "1.jpg",
"isInline": true,
"contentId": "myContentId",
"contentBytes": "validBase64Bytes"
}
Not sure whether it is a temporary issue.不知道是不是暂时的问题。 I will inform Microsoft team to check the log.我会通知微软团队检查日志。
If I am wrong for how to use the API, please definitely point out.如果我对如何使用 API 有错误,请务必指出。 Thanks.谢谢。
I will leave it here for future people to save some time to implement adding inline image.我将把它留在这里供以后的人节省一些时间来实现添加内联图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.