0

I have been developing Bot, I have configured my WaterfallDialog, the bot connects to database, get some information and creates Excel file, now I don't know how to upload the file to user. Is it not possible to upload file directly to user?

How to send attachment in bot framework in web embedded bot using c#

I followed the above post, but this provides a URL to the user or it removes the extension from the file Image of file upload to channel without extensions

Edit: I have followed both answers in the above question, the 1st answer uploads the file to the channel, but the file extension and file name is changed. So when user downloads the file they download "original" instead of "file.extension"

As requested, here is the code used.

{
    var imagePath = System.Web.HttpContext.Current.Server.MapPath(@"~\Resources\Results.xlsx");

    using (var connector = new ConnectorClient(new Uri(serviceUrl)))
    {
        var attachments = new Attachments(connector);
        var response = await attachments.Client.Conversations.UploadAttachmentAsync(
            conversationId,
            new AttachmentData
            {
                Name = "Results.xlsx",
                OriginalBase64 = File.ReadAllBytes(imagePath),
                Type = "text/xlsx"
            });

        var attachmentUri = attachments.GetAttachmentUri(response.Id);

        return new Attachment
        {
            Name = "Results.xlsx",
            ContentType = "text/xlsx",
            ContentUrl = attachmentUri
        };
    }
} 
4
  • Does this answer your question? How to send attachment in bot framework in web embedded bot using c# Commented Dec 13, 2019 at 12:00
  • As I said, I followed that question before, but when you click on download file, the file downloaded is named "original" and not "file.extension" like you would expect. Edit: After reading it over I realised that I only said I followed the URL part of the previous question Commented Dec 13, 2019 at 14:14
  • Can you post your code on what you have done so far? Commented Dec 17, 2019 at 23:43
  • Updated with the code that was used Commented Dec 19, 2019 at 10:52

1 Answer 1

2

Use internet attachment, upload your file to some host(e.g: aws s3) before send to user

private static Attachment GetInternetAttachment()
{
    // ContentUrl must be HTTPS.
    return new Attachment
    {
        Name = @"Resources\architecture-resize.png",
        ContentType = "image/png",
        ContentUrl = "https://learn.microsoft.com/en-us/bot-framework/media/how-it-works/architecture-resize.png",
    };
}
Sign up to request clarification or add additional context in comments.

3 Comments

This is how we decided to do it in the end, it is a solution, but if its possible to upload to channel, I would still prefer that. Another solution is also using Sharepoint, but that requires more integration with Azure
I suggest that solution because only internet attachment works for me, maybe a bug for other types of attachment, cannot get rid of "original" download issue
Yeah, I have opened Microsoft support on this, so I can see if we can get to the bottom of this, I will update the question and accept your answer if there is no direct solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.