botbuilder-dotnet icon indicating copy to clipboard operation
botbuilder-dotnet copied to clipboard

It's not possible to send binary data with the HttpSend activity

Open jamesemann opened this issue 2 years ago • 5 comments

Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.

Version

Latest

Describe the bug

It's not possible to send binary data with the HttpSend activity

To Reproduce

Steps to reproduce the behavior:

  1. Add a property to assign a binary value using an expression. You can use base64ToBinary as an example =base64ToBinary("<base 64 string>")
  2. Add a http send activity, try to use the above property in the body (using an expression) e.g. =dialog.myBinaryData
  3. Observe the output, you will see that it just posts the value Byte[].

Its because its converting the data to string content before posting here

https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Actions/HttpRequest.cs#L296

Expected behavior

It should allow you to post binary content.

jamesemann avatar Aug 10 '22 22:08 jamesemann

@jamesemann - Thank you for reporting this. I'll investigate and let you know what I find.

stevkan avatar Aug 13 '22 07:08 stevkan

@jamesemann - Thank you for your patience. I was able to repro the issue you are encountering. I've been testing the above and have found that the values do appear to be in the created object. If you pass in an index value like dialog.myBinaryData[0], it will return a value for that index location. You could convert myBinaryData to an array using something like subArray, which works, but then it is no longer a binary array which I'm guessing you want for the HttpSend action.

In the meantime, I need to test a few more scenarios and then connect with one of the devs on this. I will keep you posted when I know more. Based on the above info, if you should find a workaround, please let me know.

stevkan avatar Aug 18 '22 20:08 stevkan

Thanks @stevkan , yes we would specifically like to post binary data. In our example it is to service now to upload an attachment:

https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_AttachmentAPI#attachment-POST-file

We will look forward to updates on this issue - thank you!

jamesemann avatar Aug 18 '22 22:08 jamesemann

@jamesemann - Thank you for your patience. I did some additional testing and there does appear to be some issue with both the C# and JS base64ToBinary functions, though each seems to respond differently from one another.

The C# implementation appears to try to return the property type. If I convert Byte[] using the "subArray()` function and then flatten it, we can then see the values it has stored when passing in "AwUBDA==".

image

Testing using the LG and Expression Playground, it seems to return the base64 string value being read.

image

The JS implementation, when testing at the Playground, returns a collection of values.

image

Neither appears to return a binary string. This will need to be escalated so a fix can be put in place. I'm working on trying to identify who that might be.

stevkan avatar Aug 26 '22 23:08 stevkan

we have a PR so marking this as exempt from the daily DRI report

johnataylor avatar Oct 06 '22 20:10 johnataylor