【发布时间】: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