【问题标题】:Upload file to user using Bot Framework使用 Bot Framework 将文件上传给用户
【发布时间】:2019-12-21 03:45:41
【问题描述】:

我一直在开发 Bot,我已经配置了我的 WaterfallDialog,bot 连接到数据库,获取一些信息并创建 Excel 文件,现在我不知道如何将文件上传给用户。不能直接上传文件给用户吗?

How to send attachment in bot framework in web embedded bot using c#

我关注了上面的帖子,但这会为用户提供一个 URL,或者它会从文件中删除扩展名 Image of file upload to channel without extensions

编辑:我已按照上述问题中的两个答案进行操作,第一个答案将文件上传到频道,但文件扩展名和文件名已更改。因此,当用户下载文件时,他们会下载“原始”而不是“file.extension”

根据要求,这里是使用的代码。

{
    var imagePath = System.Web.HttpContext.Current.Server.MapPath(@"~\Resources\Results.xlsx");

    using (var connector = new ConnectorClient(new Uri(serviceUrl)))
    {
        var attachments = new Attachments(connector);
        var response = await attachments.Client.Conversations.UploadAttachmentAsync(
            conversationId,
            new AttachmentData
            {
                Name = "Results.xlsx",
                OriginalBase64 = File.ReadAllBytes(imagePath),
                Type = "text/xlsx"
            });

        var attachmentUri = attachments.GetAttachmentUri(response.Id);

        return new Attachment
        {
            Name = "Results.xlsx",
            ContentType = "text/xlsx",
            ContentUrl = attachmentUri
        };
    }
} 

【问题讨论】:

  • 正如我所说,我之前关注过这个问题,但是当你点击下载文件时,下载的文件被命名为“原始”而不是“file.extension”,就像你期望的那样。编辑:读完之后,我意识到我只是说我遵循了上一个问题的 URL 部分
  • 你能发布你到目前为止所做的代码吗?
  • 更新了使用的代码

标签: c# botframework


【解决方案1】:

使用互联网附件,在发送给用户之前将您的文件上传到某个主机(例如:aws s3)

private static Attachment GetInternetAttachment()
{
    // ContentUrl must be HTTPS.
    return new Attachment
    {
        Name = @"Resources\architecture-resize.png",
        ContentType = "image/png",
        ContentUrl = "https://docs.microsoft.com/en-us/bot-framework/media/how-it-works/architecture-resize.png",
    };
}

【讨论】:

  • 这就是我们最终决定这样做的方式,这是一个解决方案,但如果可以上传到频道,我仍然更喜欢。另一个解决方案也是使用 Sharepoint,但这需要与 Azure 进行更多集成
  • 我建议这个解决方案,因为只有互联网附件对我有用,可能是其他类型附件的错误,无法摆脱“原始”下载问题
  • 是的,我已经打开了微软对此的支持,所以我可以看看我们是否可以深入了解这个问题,如果没有直接的解决方案,我会更新问题并接受你的回答
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-13
  • 2019-05-07
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
  • 2021-05-28
  • 1970-01-01
相关资源
最近更新 更多