将图片文件进行base64编码
以下为两种方式,一直是直接将文件格式的转为base64,另一种则是以路径作为参数:
public void changeBase(MultipartFile file1,String path){
FileInputStream stream =null;
StringBuffer encode1 =new StringBuffer();
StringBuffer encode2 =new StringBuffer();
File file2 = new File(path);
try {
/*方法1:前端直接传文件*/
encode1 .append( Base64.getEncoder().encodeToString(file1.getBytes()));
//获取文件格式
String type = file1.getContentType();
//用于说明文件格式(可要可不要)
encode1.append("data:").append(type).append(";base64,");
/*方法2:前端传文件路径*/