当前位置:网站首页>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
边栏推荐
- [leetcode refers to the maximum profit of offer 63. Stock (medium)]
- Pytorch deep learning practice (3)
- Pycharm download and installation
- Ali has another "against the sky" container framework! This kubernetes advanced manual is too complete
- Oracle ora-01033: Oracle initialization or shutdown in progressprocess solution
- Lightweight project management ideas
- 微服务系统中服务降级
- 2. GPIO control summary (kernel driver) of nanopi M1 (Quanzhi H3)
- 不同注册中心区别
- [※ leetcode refers to offer 46. Translate numbers into strings (medium)]
猜你喜欢
Unity制作一个小星球
How Axure installs a catalog
轻量化项目管理思路
Database Experiment 5 Security Language Experiment
[leetcode refers to the two numbers of offer 57. And S (simple)]
Mixed use of Oracle column row conversion and comma truncated string
Opening conditions and process of hystrix circuit breaker and default alternative treatment
Ali has another "against the sky" container framework! This kubernetes advanced manual is too complete
CVPR2022 | 基于知识蒸馏的高效预训练
Online Excel to CSV tool
随机推荐
QT QML component library records owned by QML except basic components
C reads excel specific data into specific columns of DataGridView
Leaf Smecta
LabVIEW显示控件中内容过长设置自动滚动条
Online Excel to CSV tool
Swift import third-party library reports an error no such module““
Opening conditions and process of hystrix circuit breaker and default alternative treatment
Unity制作一个小星球
consul client客户端开发
Subcontracting of wechat applet based on uni app
OpenFeign组件的简介和使用
Maintenance of coherent PMB power supply of rofin laser hpc840
JS to get the browser and screen height
服务雪崩、服务熔断、服务降级
Correction of date conversion format error after Oracle adds a row total
[leetcode refers to offer 52. The first common node of two linked lists (simple)]
This paper solves the cross domain problem of browser
Pycharm Chinese plug-in
C# ftpHelper
成员函数和非成员函数