Microsoft bot framework: how to determine the image path that exists in the solution itself

I saved the image inside the project itself, now I would like to display the image on the hero map, so I mentioned the relative path. However, the image does not appear ....

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

But when I referenced the image from some website and mentioned the same path on the page as shown below, the image appeared.

 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 save the image in the project folder?

+7
source share
1 answer

This is a very old question, but, nevertheless, they brought me here. 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 svg you can skip base64 encoding:

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

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

. Microsoft #.

0

Source: https://habr.com/ru/post/1648311/


All Articles