Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft bot framework : How to define the image path which exists in the solution itself

Tags:

bots

I have stored the image inside the project itself, now I would like to display the image on the hero card, so I have mentioned the relative path. However the image is not appearing....

 List<CardImage> cardImages = new List<CardImage>();
 cardImages.Add(new CardImage(url: "~/duck-on-a-rock.jpg", alt:"image1"));

But when I referred the image from some website and mention the same path on the page like below that time the image is appearing.

 List<CardImage> cardImages = new List<CardImage>();
 cardImages.Add(new CardImage(url: "http://www.publicdomainpictures.net/pictures/30000/t2/duck-on-a-rock.jpg", alt:"image1"));

Is it not possible to keep the image inside the project folder?

like image 393
Elamparithi Chandrasekaran Avatar asked Jul 19 '16 01:07

Elamparithi Chandrasekaran


1 Answers

This is a super old question, but google me brought here nonetheless. The solution I came across was to create a data url for your local resource. In node.js:

  const imageData = fs.readFileSync(path.join(__dirname, '../resources/logo.png'));
  const base64Image = Buffer.from(imageData).toString('base64');

  const inlinePng = {
      name: 'logo.png',
      contentType: 'image/png',
      contentUrl: `data:image/png;base64,${ base64Image }`
  };

With an svg, you can skip the base64 encode:

const svgData = fs.readFileSync(path.join(__dirname, './resources/logo.svg'));

const inlineSvg = {
  name: 'logo',
  contentType: 'image/svg',
  contentUrl: `data:image/svg+xml;utf8,${ svgData }`,
};

See Microsoft's docs for reference and C# samples.

like image 57
PartyLich Avatar answered Sep 16 '22 17:09

PartyLich