我试图在Bot框架中的Adaptive中放置一个图像,如下所示:
card.Body.Add(new AdaptiveImage()
{
Type = "Image",
Url = new Uri(pictureUrl),
Size = AdaptiveImageSize.Large
});起作用了。问题在于Url。我以Base64格式从外部web服务获取图像。但是有时我会得到太大的图像,所以我得到了The uri string is too long异常。
有办法解决这个问题吗?例如,启用以字节为单位的自适应卡中的图像。
发布于 2019-05-10 15:25:23
谢谢你报道这个问题。根本原因是pictureUrl比.NET的最大Uri长度长。我们是在这里跟踪修复。
有一个非常简单的解决方法,因为限制发生在.NET C#库中,您只是使用这个库来简单地创建卡片,但是WebChat并不使用C#库来显示卡片(它使用JS库,JS/HTML没有长度限制!)因此,在您的情况下唯一不起作用的是生成JSON.但有一个简单的解决办法!
解决方案:定义以下类,扩展AdaptiveImage,添加LongUrl属性(该属性写入JSON中的同一个url属性)。
public class AdaptiveImageWithLongUrl : AdaptiveImage
{
[JsonProperty(PropertyName = "url", Required = Required.Always)]
public string LongUrl { get; set; }
}然后,在分配长urls时使用新的图像类和新属性!
// 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"
};https://stackoverflow.com/questions/55663963
复制相似问题