当前位置:网站首页>Convert pictures on OSS to Base64 encoding
Convert pictures on OSS to Base64 encoding
2022-04-23 22:06:00 【Juicy and flavorful】
Use Java according to oss The address where the picture is saved on is converted to Base64 code
import sun.misc.BASE64Encoder;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class OssUrlImgBase64Transfer {
public static String getBase64(String ossUrl) {
InputStream in = null;
final ByteArrayOutputStream data = new ByteArrayOutputStream();
// Read image byte array
try {
URL url = new URL(ossUrl);
final byte[] by = new byte[1024];
// Create links to get pictures
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
in = conn.getInputStream();
int len = -1;
while ((len = in.read(by)) != -1) {
data.write(by, 0, len);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
// For byte arrays Base64 code
BASE64Encoder encoder = new BASE64Encoder();
// return Base64 Encoded byte array string
String encode = encoder.encode(data.toByteArray());
encode = encode.replaceAll("[\\s*\t\n\r]", "");
return encode;
}
}版权声明
本文为[Juicy and flavorful]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232159112720.html
边栏推荐
- On nanopi M1 (Quanzhi H3) kernel driver programming HelloWorld (compilation mode I)
- Daily operation and maintenance knowledge -- 1
- leetcode 2223 — 构造字符串的总得分和
- MySQL 回表
- 轻量化项目管理思路
- [leetcode refers to offer 25. Merge two sorted linked lists (simple)]
- Ribbon 服务调用
- 2022 - 04 - 24 Daily: Current Progress and Open Challenges of Applied Deep Learning in Biological Sciences
- 构造函数 & 析构函数
- consul 关闭健康监控检查
猜你喜欢
随机推荐
JS to get the browser and screen height
A method of asynchronous response of application service through load balancing
1. Summary of GPIO control of nanopi M1 (Quanzhi H3) based on wiringpi
OpenFeign 组件说明
五个拿来就能用的炫酷登录页面
Oracle ora-01033: Oracle initialization or shutdown in progressprocess solution
Opening conditions and process of hystrix circuit breaker and default alternative treatment
关于DateUtil时间工具类造成程序报错
资本追逐Near生态
降级和熔断总结
C reads excel specific data into specific columns of DataGridView
服务注册中心和Ribbon组件回顾
Hirschmann display maintenance computer controller repair
consul 开启健康监控检查
不同注册中心区别
21. Basic usage of MariaDB
Swift import third-party library reports an error no such module““
3、 Zygote start process
Hystrix简介和服务端熔断的实现
RestTemplate 服务调用









