将二进制文件转换为 Base64 字符串 [英] Converting binary file to Base64 string

查看:38
本文介绍了将二进制文件转换为 Base64 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要即时将上传的二进制文件转换为 base64 字符串格式.我正在使用 ASP,Vbscript.使用 Midori 的组件进行 base64 转换.对于小尺寸文件(<20K),性能还可以.但是当它超过 75 或 100K 时,它就完全丢失了.有没有什么有效的方法可以将大二进制文件(2MB)转换为base64字符串格式?

I need to convert uploaded binary files to base64 string format on the fly. I'm using ASP, Vbscript. Using Midori's component for base64 conversion. For small size files (<20K) the performance is okay. But when it exceeds 75 or 100K, its totally lost. Is there any efficient way to convert big binary files (2MB) to base64 string format?

提前致谢,肯尼

推荐答案

我已经通过实现一个 .net 组件来转换为 base64 字符串解决了这个问题.困难的部分是从 ASP 发送到 .net COM 的二进制数据作为字符串接收.Convert.ToBase64() 仅接受 byte[].所以我尝试将字符串转换为字节[].

I have solved this issue by implementing a .net component for converting to base64 string. The hard part is the binary data sent to the .net COM from ASP is received as a string. Convert.ToBase64() accepts only byte[]. So I tried converting string to byte[].

但是 .net 中可用的编码(Unicode、ASCII、UTF)不能正常工作.在使用这些编码时,存在数据丢失.最后我通过使用 StringReader 对象来完成它.逐个字符(16位)读取字符并将它们转换为(8位)字节[]数组.

But the encoding available in .net (Unicode, ASCII, UTF) doesn't works fine. There are data loss, while these encodings are used. Finally I get it done by using StringReader object. Read char by char(16 bit) and converted them to (8 bit) byte[] array.

而且性能最好.

问候,湿婆.

这篇关于将二进制文件转换为 Base64 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆