botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Skype: Inbound attachment has no name

Open tpernice opened this issue 10 years ago • 7 comments

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);
        }

tpernice avatar Nov 29 '16 16:11 tpernice

Which version of bot SDK are you using?

almostWaldo avatar Dec 20 '16 17:12 almostWaldo

It's v3.4

tpernice avatar Dec 21 '16 13:12 tpernice

yeah, it should work there. So, what skype clients did you try? Some devices don't support file names

almostWaldo avatar Dec 21 '16 14:12 almostWaldo

Skype Desktop for Windows latest version.

tpernice avatar Dec 21 '16 14:12 tpernice

Hello Tom. Could you send your bot ID?

almostWaldo avatar Jan 09 '17 12:01 almostWaldo

@tpernice, are you still experiencing this issue? if yes, can you send your bot id?

Andrea-Orimoto avatar Feb 14 '17 19:02 Andrea-Orimoto

closed as old

konstlut avatar Mar 10 '17 14:03 konstlut