[Question] Show images from Database in Hero Cards
Hello Based on my business logic I want to fetch an image from database and use it on my Hero Card. But hero card accepts the image url as the input. How can I achieve this without url or when an image has to be fetched dynamically from a database or some other source.
@neetgupta7 Are you using .NET or Node SDK?
.net
@neetgupta7 This repository is for questions about BotBuidler SDK. If you'd like to learn about working with databases, try Stack Overflow or Google search.
Not sure if my description was not clear enough. Hero cards accepts https URL for images, what should I do if my image is not hosted in a website but in present in a database. How do I show them.
Hi @neetgupta7
You can add another web api controller to the bot that returns the images, and use that url. Here is an example of how to return an image from a database:
[HttpGet]
public HttpResponseMessage Get(Guid id)
{
HttpResponseMessage result = null;
try
{
var artwork = _repository.GetArtwork(id);
if (artwork == null)
{
result = Request.CreateResponse(HttpStatusCode.Gone);
}
else
{
// sendo file to client
byte[] bytes = artwork.artworkMeta ;
result = Request.CreateResponse(HttpStatusCode.OK);
result.Content = new ByteArrayContent(bytes);
result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = artwork.artworkName;
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
}
return result;
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.Gone);
}
}
from: https://stackoverflow.com/questions/41165240/return-image-from-db-and-display-with-net-api-and-angularjs
I hope this helps.
The Microsoft Bot Framework team prefers that how to questions be submitted on Stack Overflow. The official Bot Framework Github repo is the preferred platform for submitting bug fixes and feature requests.
var bytes = System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Content/image.jpg"));
string imageData = Convert.ToBase64String(bytes, 0, bytes.Length);
HeroCard heroCard = new HeroCard()
{
Title = Name,
Subtitle = Address,
Images = new List
I had the same issue and after having a look at the SendAttachmentBot example (available on github by microsoft) came to know that you can simply put image data in the "Url" parameter and it is displayed just fine.