Currently, I'm utilizing Ajax to fetch images from a remote server. Initially, I attempted this by directly using the URL of the remote server - resulting in the returned image being a string (given that's how Ajax communicates). To rectify this, I utilized Javascript functions such as fromCharCode and CharCodeAt to convert the data back to binary, followed by window.btoa() to display it successfully. Following this success, my focus shifted towards transferring this image through an overlay network (P2P).
In order to achieve this, I intercepted the Ajax request, transmitted it to the server via the P2P network, and retrieved the response in []byte array form. However, I now face the challenge of determining the appropriate method to convert the byte array into a string type before feeding it back to the calling Ajax client. Previous attempts using Base64 encoding or simple byte array conversion have resulted in incorrect image display.
I'm curious if anyone has encountered a similar scenario and would greatly appreciate any insights or feedback on this matter. Thank you in advance.