1

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

API Body :

{"_ProxyDetails":{"Password":"test@123","ProxyID":0,"ReturnType":"JSON","UserName":"user@itsm.com","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 byte array using built in JavaScript library only. Can anyone help me to convert this image to bytearray type?

enter image description here

Arulvelu
  • 79
  • 1
  • 7
  • possible duplicate of https://stackoverflow.com/questions/9258932/how-to-convert-image-to-byte-array-using-javascript-only-to-store-image-on-sql-s – Naga Sai A Nov 05 '18 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. – Arulvelu Nov 08 '18 at 09:12
  • JSON doesn't understand bytearray. The field, as presented in your API Body example, is a unicode string. – Ouroborus Nov 12 '18 at 13:01
  • @Ouroborus . Can you assist me to figure out how this byte array can be sent using API – Arulvelu Nov 12 '18 at 13:05
  • 1
    Once you've converted the image to a data url as in https://stackoverflow.com/questions/9258932/how-to-convert-image-to-byte-array-using-javascript-only-to-store-image-on-sql-s , 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])` – Ouroborus Nov 12 '18 at 13:20
  • @Arulvelu did you get the answer? – MSD Dec 19 '20 at 19:36

0 Answers0