【发布时间】:2017-07-28 14:40:11
【问题描述】:
我正在 BOT 模拟器中上传附件,上传附件后我将其转换为 base64,以将其传递给我们的服务。 我从路径 D:\Images\MobileRequest.PNG 中选择了这个附件,但是在将其上传到 BOT 应用程序后,它显示附件的路径为http://127.0.0.1:44185/v3/attachments/ne7djbemc9f40bifi/views/original/MobileRequest.PNG,因为该路径上没有图像,因此在将图像转换为 base64 时,它会抛出一个错误,因为“不支持 URI 格式。”。
如何在 BOT 应用程序中获取实际物理路径,即“D:\Images\MobileRequest.PNG”。 以下是我的 BOT 应用程序中的代码
var dialog = new PromptDialog.PromptAttachment("Please attach screenshot ", "Sorry, I didn't get the attachment. Try again please.", 2);
context.Call(dialog, afterUpload);
private async Task afterUpload(IDialogContext context, IAwaitable<IEnumerable<Attachment>> result)
{
IEnumerable<Attachment> attach = await result;
string filePath = attach.FirstOrDefault().ContentUrl + "/" + attach.FirstOrDefault().Name;
context.UserData.SetValue("filePath", filePath);
}
string filePath = string.Empty;
context.UserData.TryGetValue("filePath", out filePath);
using (System.Drawing.Image image = System.Drawing.Image.FromFile(filePath))
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, image.RawFormat);
byte[] imageBytes = m.ToArray();
attach1 = Convert.ToBase64String(imageBytes);
}
}
【问题讨论】:
标签: bots botframework