【问题标题】:Use local image after publishing Chatbot发布聊天机器人后使用本地图片
【发布时间】:2018-03-19 12:33:51
【问题描述】:

我正在创建使用本地图像的英雄卡,并且在本地使用模拟器时可以使它们正常工作,但在发布到 azure 后无法正常工作。我正在尝试将图像转换为 base64 以使用它。

List<CardImage> cardImages = new List<CardImage>
{
  new CardImage(url: ImageToBase64(thisService.Type.ToString()))
};

(...)

HeroCard plCard = new HeroCard()
{
  Title = $"{titles[thisService.Type.ToString()]}",
  Subtitle = $"Serviço {thisService.Frequency.ToString()} agendado para {thisService.Date.ToLongDateString()} às {thisService.Date.ToShortTimeString()}.",
  Images = cardImages,
  Buttons = cardButtons
};

(...)

public static string ImageToBase64(string imageName)
{
  var path = HostingEnvironment.MapPath($"/Resources/Images/{imageName}.PNG");
  Byte[] bytes = File.ReadAllBytes(path);
  string base64String = Convert.ToBase64String(bytes);
  return "data:image/png;base64," + base64String;
}

azure 门户频道上出现的错误如下:

{"error":{"message":"(#100) name_placeholder[elements][0][image_url] should represent a valid URL","type":"OAuthException","code":100,"fbtrace_id":"BLoacoRFVy7"}}

这可能吗?

【问题讨论】:

    标签: c# file azure url botframework


    【解决方案1】:

    您似乎正在尝试使用仅支持托管图像的 Facebook 频道。如果您在 Azure 上,则可以使用 blobstorage 来托管您的图像并将此公共链接用于您的图像。但是,任何托管图像都可以使用。

    【讨论】:

    • 是的,我就是这么做的,而且效果很好,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    • 2019-11-23
    • 1970-01-01
    相关资源
    最近更新 更多