P2P Ajax图像传输
我正在使用 Ajax 从远程服务器检索图像。首先,我直接使用远程服务器的 URL 进行尝试 - 返回的图像是一个字符串(因为这就是 Ajax 通信的方式)。我使用 JavaScript fromCharCode 和 CharCodeAt 将数据转换回二进制,然后使用 window.btoa() 显示它。这有效。然后我想通过覆盖网络(P2P)传输这个图像。我拦截 Ajax 请求,通过 P2P 网络将其传输到服务器,然后在 []byte 数组中检索响应。但现在我需要知道在将字节数组反馈给调用 Ajax 客户端之前应该将其转换为什么类型的字符串。如果我使用 Base64 或简单地将字节数组转换为字符串,则它无法正确显示图像。
有人尝试过使用类似的东西吗?
我将非常感谢任何反馈。谢谢
I am using Ajax to retrieve images from a remote server. First I try this directly using the URL of the remote server - the returned image is a string(since that's how Ajax communicates). I use the Javascript fromCharCode and CharCodeAt to convert the data back to binary and then the window.btoa() to display it. This works. Then I want to transfer this image through an overlay network (P2P). I intercept the Ajax request, transfer it to the server through the P2P network and then retrieve the response in []byte array. But now I need to know to what type of string I should convert the byte array before I feed it back to the calling Ajax client. If I use Base64 or simply convert the byte array to string it does not display the image correctly.
Anyone has tried working with something like this before?
I will appreciate any feedback very much. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JavaScript 没有不同种类的字符串。
所需的字符集与网页编码的字符集相同,最好是 UTF-8。
您是否将 P2P 服务器发送的响应与原始服务器发送的响应进行比较?是否缺少某种包装器,或者可能存在重要的 MIME 类型差异?
Javascript doesn't have different kinds of strings.
The desired character set will be the same one the web page is encoded in, ideally UTF-8.
Have you compared the response sent by the P2P server to the response sent by the original server? Is there some kind of wrapper that's missing, or perhaps an important MIMEtype difference?