栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

java将hdfs上的图片转为base64返回给前端

java将hdfs上的图片转为base64返回给前端

 将hdfs上面的图片转化为base64传给前端

public static void main(String[] args) throws IOException {
	String hdfsPath = "hdfs://192.168.0.0:9200/tmp/test/tupian.jpg";
	Path path = new Path(hdfsPath);
	Configuration configuration = new Configuration();
	FSDataInputStream fsDataInputStream = null;
	FileSystem fileSystem = null;
	// 定义一个字符串用来存储文件内容
	fileSystem = path.getFileSystem(configuration);
	fsDataInputStream = fileSystem.open(path);

	int oop = (int) ((HdfsDataInputStream)fsDataInputStream).getVisibleLength();
	byte[] b = new byte[oop];

	fsDataInputStream.read(b);
	String res = getImagebase64(b,"jpg")
}

//type:jpg
private static String getImagebase64(byte[] context,String type) {
	String imageData = "";
	base64Encoder encoder = new base64Encoder();
	// 通过base64来转化图片
	imageData = encoder.encode(context);
	imageData = imageData.replaceAll("n", "").replaceAll("r", "");
	imageData = "data:image/"+type+";base64,"+imageData;
	return imageData;
}

https://blog.csdn.net/qq_41212530/article/details/104294956

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/630431.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号