我正在尝试将图像放入 Bot 框架中的自适应卡中,如下所示:
card.Body.Add(new AdaptiveImage()
{
Type = "Image",
Url = new Uri(pictureUrl),
Size = AdaptiveImageSize.Large
});
它正在发挥作用。问题出在 Url 上。我从外部 Web 服务获取 Base64 格式的图像。但有时我得到的图像太大,所以我得到The uri string is too long
例外。
有什么办法可以解决这个问题吗?例如,启用将图像以字节为单位放入自适应卡中。
感谢您报告此问题。根本原因是 pictureUrl 比 .NET 的最大 Uri 长度长。是跟踪在这里修复这个问题 https://github.com/microsoft/AdaptiveCards/issues/2881.
有一个非常简单的解决方法可用,因为限制发生在您用来简单创作卡片的 .NET C# 库中,但 WebChat 不使用 C# 库来显示卡片(它使用 JS 库,并且 JS /HTML 没有长度限制!)。因此,在您的情况下唯一不起作用的是生成 JSON...但有一个简单的修复方法!
解决方法:
定义以下类,扩展AdaptiveImage
,添加一个LongUrl
属性(写入相同的url
JSON 中的属性)。
public class AdaptiveImageWithLongUrl : AdaptiveImage
{
[JsonProperty(PropertyName = "url", Required = Required.Always)]
public string LongUrl { get; set; }
}
Then,在分配长网址时使用新的图像类和新属性!
// A data URL that's longer than .NET max length
string actualUrl = "data:image/gif;base64," + string.Join("", new int[120000].Select(i => "A")) + "end";
AdaptiveCard card = new AdaptiveCard("1.0")
{
Body =
{
new AdaptiveImageWithLongUrl()
{
LongUrl = actualUrl
}
}
};
// Place the JObject in the attachment!
var attachment = new Attachment()
{
Content = card,
ContentType = "application/vnd.microsoft.card.adaptive",
Name = "cardName"
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)