Ich habe Web-API-Service:Wie kann ich Datei an Nachricht mit Microsoft Bot Framework anhängen?
[ActionName("download")]
[HttpGet]
public HttpResponseMessage Download()
{
var stream = new FileStream(HostingEnvironment.MapPath("~/tmp/") + "doc.pdf", FileMode.Open);
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(stream)
};
result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
{
FileName = document.Name + "." + document.AssociatedApplication.Extension
};
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return result;
}
Bot Code:
if (message.Text.StartsWith("/d"))
{
var contentType = "application/pdf";
var attachment = new Attachment(contentType, "https://localhost/api/documents.download");
var response = await client.GetAsync("https://localhost/api/documents.download");
var data = await response.Content.ReadAsByteArrayAsync();
System.IO.File.WriteAllBytes(HostingEnvironment.MapPath("~/tmp/") + document.Name + "." + document.Extension, data);
var stream = System.IO.File.ReadAllBytes(HostingEnvironment.MapPath("~/tmp/") + document.Name + "." + document.Extension);
attachment.Content = stream;
var msg = message.CreateReplyMessage("This is your document: ");
msg.Attachments = new[] { attachment };
await context.PostAsync(msg);
}
Wenn ich dann Inhaltstyp auf dem Server und Client "image/png" und senden PNG-Bild vom Server zum Client ändern Dieses Beispiel funktioniert perfekt - im Bot Framework Emulator habe ich Text "This is your document:" und Bild erhalten.
Aber wenn ich versuche, ein PDF-Dokument mit dem Inhaltstyp "application/pdf" oder "application/octet-stream" zu senden und auf den Client mit dem Inhaltstyp "application/pdf" zu bekommen, dann bin ich auf dem Bot Framework Emulator Nachricht wie folgt aus:
Dies ist Ihr Dokument: (https://localhost/api/documents.download)
ist das möglich im Gespräch „echten“ Dokument statt Link zum Download zu erhalten (wie es mit Bildern funktioniert)?
PS: This question funktioniert nur für "image/png" oder ähnliche Inhaltstypen.