【发布时间】:2016-12-25 02:44:41
【问题描述】:
//If the user uploaded an image, read it, and send it to the Vision API
if (activity.Attachments.Any() && activity.Attachments.First().ContentType.Contains("image"))
{
//stores image url (parsed from attachment or mess`enter code here`age)
string uploadedImageUrl = activity.Attachments.First().ContentUrl; ;
uploadedImageUrl = HttpUtility.UrlDecode(uploadedImageUrl.Substring(uploadedImageUrl.IndexOf("file=") + 5));
using (Stream imageFileStream = File.OpenRead(uploadedImageUrl))
{
try
{
analysisResult = await visionClient.AnalyzeImageAsync(imageFileStream, visualFeatures);
}
catch (Exception e)
{
analysisResult = null; //on error, reset analysis result to null
}
}
}
//Else, if the user did not upload an image, determine if the message contains a url, and send it to the Vision API
else
{
try
{
analysisResult = await visionClient.AnalyzeImageAsync(activity.Text, visualFeatures);
}
catch (Exception e)
{
analysisResult = null; //on error, reset analysis result to null
}
}
我正在尝试上面的代码。我从这里得到代码:https://docs.botframework.com/en-us/bot-intelligence/vision/#example-vision-bot。
按原样,代码可以在本地运行时执行它可以执行的操作,但是在我将机器人发布到 Azure 并从那里运行后,从上传的文件中读取图像的 URL 不起作用。
我尝试通过将 Visual Studio 直接附加到我在 Azure 中发布的 webapp bot 来进行调试。看起来 webapp 无法从 Azure 服务器临时存储位置读取存储图像的 URL,或者无法访问临时存储位置。
这一行:
uploadedImageUrl = HttpUtility.UrlDecode(uploadedImageUrl.Substring(uploadedImageUrl.IndexOf("file=") + 5));
显示这个值: "https://bcattachmentsprod.blob.core.windows.net/at4984/Gv4cOx6OdSl-原创"
那么,这一行:
using (Stream imageFileStream = File.OpenRead(uploadedImageUrl))
将值更改为: "s://bcattachmentsprod.blob.core.windows.net/at4984/Gv4cOx6OdSl-original"
然后它就停止了。
有人遇到过这样的问题吗?我该如何解决这个问题?
谢谢!
【问题讨论】:
标签: c# azure botframework microsoft-cognitive