microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

[Question] The request content length exceeded limit of 262144 bytes #3477

Closed AyandaSabasaba closed 7 years ago

AyandaSabasaba commented 7 years ago

I have my bot hosted in Azure app services, I have a large pdf document I am sending through to the user When the bot sends the message with the attachment: Throws an exception : Microsoft.Rest.HttpOperationException: The request content length exceeded limit of 262144 bytes

var attachmentData = Convert.ToBase64String(File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/App_Data/Test2.pdf"));

                var attachment = new Attachment()
                {
                    Name = "doc.pdf",
                    ContentType = "application/octet-stream",
                    ContentUrl = $"data:application/octet-stream;base64,{attachmentData}"
                };

                replyMessage.Attachments.Add(attachment);

Please help.

JasonSowers commented 7 years ago

How big is the file? It seems you will not be able to send it because it is too large like the error message says. Are you able to break it up into smaller files and send them?

AyandaSabasaba commented 7 years ago

There are options such has storing the file in azure blob and send the download URL to the bot user. I was looking for some suggestions around that like streaming bits and bits of bytes

JasonSowers commented 7 years ago

I really think hosting the file somewhere and providing the download link is the best solution here.

AyandaSabasaba commented 7 years ago

Security is my issue it's sensitive information contained in the file, serialising the file on the fly is more secured than providing a link

XyzFreak commented 7 years ago

@AyandaSabasaba Did you try to send attachments in Skype (i mean files).

gcfabri commented 7 years ago

I am trying to send a PDF smaller than 256Kb encoded to base64 and it does not work. Is there another way to send PDF file without storing and sending the URL? I see this option in the documentation.Is it the same thing that send data URI?

JasonSowers commented 7 years ago

@gcfabri are you trying to send the file from the bot or from the user? Also what channel are you trying this on?

gcfabri commented 7 years ago

@JasonSowers From bot to the user and I am using Botkit + BotFramework (Facebook, Telegram, Web and Skype). I think I've settled my doubt, the file I was trying to send is smaller than 256kB indeed, however the size of the base64 string exceeds the limit, resulting in an error: 'Bad Request'. In my case, the workaround was store the files and send only the URI to the user.

JasonSowers commented 7 years ago

Glad you were able to work around this

JWiersema commented 6 years ago

I get this same error when talking to the Bot in WebChat. I don't get the error in MS Teams. Are the limits different for each client? What is the recommend response message size and how do you check it correctly? The error occurs when giving back a Carousel with max 10 items, which I believe is the max size.

JWiersema commented 6 years ago

PS: It works with max 5 carousel items. Still, it's not cool that these limits are different for each client

anndreyy commented 3 years ago

Updating just out of curiosity, I also only have the error on the webchat, on teams the error doesn't happen.

JasonSowers commented 3 years ago

The reason this happens is bot framework does not control the limits the client/channel imposes on file transfers. If you are having a problem with any channel check that channel's documentation. Bot framework/Microsoft is not able to tell Facebook messenger's client what to do, Facebook's developers do, or whatever channel. If the problem is with WebChat file an issue against the WebChat repository.

Let me answer the obvious questions here, well if teams it a Microsoft product why is it different then?

Microsoft is a gigantic global organization with a lot of employees. It's easy to make the assumption that everyone at Microsoft works for the same leadership in the same organization in the same room and everything should just work together seamlessly. So, the Teams team and the bot framework team are not working side by side making sure 100% of things are in lockstep. Products also change things, and not everyone is able to keep up to date with every single change happening for all of Microsoft's offerings. Teams probably has a reason they didn't make the file size limit the same as WebChat. Just like you wouldn't expect an AWS developer to know why your Amazon package is late.

eeronjohn commented 5 months ago

Hi, what should be the size limit in sending attachments from bot to user for MS teams? Can't find the documentation for it.