You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MS Teams机器人添加PDF附件时提示‘未知附件类型’错误求助

问题原因及解决方案

核心原因

Teams机器人的附件机制不支持使用data:application/pdf;base64,...这种内嵌的base64数据URI作为content_url,这种格式会被识别为未知的附件类型,从而抛出Unknown attachment type错误。

解决办法

方法1:使用公开可访问的文件URL

将PDF文件上传到支持公开访问的存储服务(如Azure Blob Storage、云存储等),获取文件的公开URL,替换代码中的content_url:

修改_get_inline_attachment方法:

def _get_inline_attachment(self) -> Attachment:
    # 替换为你的PDF文件公开访问URL
    public_pdf_url = "https://your-storage-service.com/TEST.pdf"
    return Attachment( 
        name="TEST.pdf", 
        content_type="application/pdf", 
        content_url=public_pdf_url,
    )        

方法2:通过Teams文件上传接口(推荐)

如果需要在Teams内部管理文件,可以调用Teams的文件上传API,将PDF上传到用户的OneDrive for Business或Teams团队文件库,再生成对应的附件链接。这种方式更符合Teams的生态规范,示例代码框架如下:

# 简化示例,需结合Teams文件上传API实现
async def upload_pdf_to_teams(self, turn_context: TurnContext):
    # 1. 调用Teams API获取上传会话
    # 2. 上传PDF文件到会话指定的URL
    # 3. 获取文件的访问链接
    file_url = "https://graph.microsoft.com/v1.0/teams/{team-id}/drive/items/{item-id}"
    return Attachment(
        name="TEST.pdf",
        content_type="application/pdf",
        content_url=file_url
    )

额外注意点

  • 代码中变量名dencoded_string是拼写错误,应为decoded_string,虽然这不是报错的直接原因,但建议修正以避免后续问题。
  • 确保content_type严格设置为application/pdf,大小写和格式不能出错。

内容的提问来源于stack exchange,提问作者bitterjam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 01:01:22