用Gwt转换Base64字符串 [英] Convert Base64 String with Gwt

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

问题描述

如何使用Gwt客户端代码将base64字符串转换为字节数组?

How to convert a base64 String to byte array with Gwt client side code?

此链接显示针对base64的编码解码,但不针对byte []数组

This link shows a encode decode, for base64 but not to byte[] array

https://snipt.net/tweakt/gwt-base64/

推荐答案

您有两个选择:

1-使用本机JS方法 btoa atob ,然后将返回的字符串转换为Java byte[]数组:

1- Use native JS methods btoa and atob, and convert the returned string to a java byte[] array:

 native String btoa(String b64) /*-{
    return btoa(b64);
 }-*/;
 ...
 byte[] result = btoa(myBase64Data).getBytes();

2-使用Base64算法的纯Java实现.您可以只复制 Base64Utils.java 包含在gwt-user.jar中,然后将其复制到您的客户端软件包中,并使用其方法:

2- Use a pure java implementation of Base64 algorithm. You can just copy the Base64Utils.java included in the gwt-user.jar, and copy it to your client package, and use its methods:

 import my.project.namespace.client.Base64Utils;
 ...
 byte[] result = Base64Utils.fromBase64(myBase64Data);

通常,对于IE10,FF和Webkit浏览器,我使用#1,对于旧的IE使用#2.

Normally I use #1 for IE10, FF and webkit browsers, and #2 for old IE.

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

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