将媒体(图像/视频)转换为Base64.encodeToString [英] Convert Media (Image/video) to Base64.encodeToString

查看:796
本文介绍了将媒体(图像/视频)转换为Base64.encodeToString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All



从我的Android应用程序中,我需要将Media(视频,图像)发送到部署了WCF服务的Web服务器以保存图像服务器端。请求和响应类型是Web方法的JSON ...



问题是在应用程序中,当我将图像转换为字节数组然后转换为base64字符串中,编码的字符串的长度变大显著...

<峰; br /> 
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ.....and so-on





相对较小的图片也只有16 Kb



有没有更简洁的方法来做到这一点,而不是在服务器端发送大型编码的base 64字符串,然后再解码它以获取图像/视频??



谢谢:)

解决方案

将数据转换为base64应该会产生相当大的数据块。 (你还能期待什么?)除了使用一些只需要8位或7位文本数据的传输的情况之外,它没有任何意义。一个例子是以独立于邮件消息本身的内容类型(charset部分)的方式通过电子邮件发送数据。



学习使用WCF的数据传输,你可以从这里开始: https://msdn.microsoft.com/ en-us / library / ee473426%28v = vs.110%29.aspx [ ^ ]。



-SA

Hello All

From my android app,I need to send Media(video,image) to a web server having WCF services deployed to save the image on the server end. The request and response type is JSON for the web methods...

The issue is that in the app, when i convert image to byte array and then to base64 string, the length of the encoded string becomes significantly large...

<br />
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ.....and so-on 



for a relatively small image too of just 16 Kb

Is there a cleaner way to do this rather than sending large encoded base 64 string on the server side and then again decoding it to get the image/video??

Thanks :)

解决方案

Converting data to base64 is supposed to make considerably larger chunk of data. (What else would you possibly expect?) It just makes no sense except the cases when it is done to use some transport which requires only 8-bit or 7-bit text data. One example is sending data in e-mail the way independent from the content type (charset part of it) of the mail message itself.

To learn data transfer using WCF, you can start here: https://msdn.microsoft.com/en-us/library/ee473426%28v=vs.110%29.aspx[^].

—SA


这篇关于将媒体(图像/视频)转换为Base64.encodeToString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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