1

The idea of the task is to create an incident in the ticketing platform and attach a screenshot to the ticket created using a chatbot. For the attachment to be done for the ticket created, I am using an upload attachment API which accepts the image in byte array type only.

API Body:

{
"_ProxyDetails": {
   "Password":"test@123",
   "ProxyID":0,
   "ReturnType":"JSON",
   "UserName":"[email protected]",
   "OrgID":1,
   "TokenID":""
},
"eModule":"IM",
"TicketID":14487, 
"FileByte":"", 
"AttachmentFileName":"testtextfile.txt"
}

Where FileByte needs to be a byte array. I need the image to be converted to a byte array using the built-in JavaScript library only. Can anyone help me to convert this image to byte array type?

enter image description here

6
  • possible duplicate of stackoverflow.com/questions/9258932/… Commented Nov 5, 2018 at 21:32
  • Hey adrian , i have seen the question which naga pointed in the above comment. In that question they are converting it to base 64 string and sending the same String to C# code for byte array conversion. I dont need that kind of conversion. I would require a pure JS conversion only as i am doing this on a platform which supports JS only . So can you help me to convert the same using JS alone. Commented Nov 8, 2018 at 9:12
  • JSON doesn't understand bytearray. The field, as presented in your API Body example, is a unicode string. Commented Nov 12, 2018 at 13:01
  • @Ouroborus . Can you assist me to figure out how this byte array can be sent using API Commented Nov 12, 2018 at 13:05
  • 1
    Once you've converted the image to a data url as in stackoverflow.com/questions/9258932/… , you can take that, trim off the beginning portion, and convert the rest of it to a binary string. E.g. atob(getBase64Image().split(',')[1]) Commented Nov 12, 2018 at 13:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.