Skype: Inbound attachment has no name
Hi, I am trying to get an attachment from the user, but I found out that the "name" property of the Attachment class is always empty, and moreover the "ContentType" is always "application/octet-stream". How can I get the file name?
Tom
private async Task geAttachment(IDialogContext context, IAwaitable<IEnumerable<Attachment>> result)
{
string id = "";
string path = HttpContext.Current.Server.MapPath("~/attachments");
IEnumerable<Attachment> list = await result;
Attachment attachment = list.FirstOrDefault();
string filename = attachment.Name;
string url = attachment.ContentUrl;
string contentType = attachment.ContentType;
Uri uri = new Uri(url);
using (HttpClient httpClient = new HttpClient())
{
// Skype attachment URLs are secured by a JwtToken, so we need to pass the token from our bot.
if (uri.Host.EndsWith("skype.com"))
{
var token = await new MicrosoftAppCredentials().GetTokenAsync();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
}
context.PrivateConversationData.TryGetValue<string>("ID", out id);
var responseMessage = await httpClient.GetAsync(url);
responseMessage.EnsureSuccessStatusCode();
// Read response asynchronously and save asynchronously to file
using (FileStream fileStream = new FileStream(path + @"\" + filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
await responseMessage.Content.CopyToAsync(fileStream);
}
}
await context.PostAsync(path + @"\" + filename);
await context.PostAsync(contentType);
context.Wait(MessageReceived);
}
Which version of bot SDK are you using?
It's v3.4
yeah, it should work there. So, what skype clients did you try? Some devices don't support file names
Skype Desktop for Windows latest version.
Hello Tom. Could you send your bot ID?
@tpernice, are you still experiencing this issue? if yes, can you send your bot id?
closed as old