Minio上传html文件
内容浏览乱码问题,下载下来是正常编码。解决方法:
1、引入 文件内编码识别
<dependency> <groupId>com.github.jiangxincode</groupId> <artifactId>cpdetector</artifactId> <version>1.0.10</version> </dependency>
2、加入代码
if("text/html".equals(contentType)){ try { File tempFile = File.createTempFile("temp","."+suffix); FileOutputStream outputStream = new FileOutputStream(tempFile); outputStream.write(file.getBytes()); outputStream.close(); // IoUtil.copy(inputStream, tempFile); // 判断文件编码 String charsetName = ReadUtil.getCharsetName(tempFile); contentType=contentType+";charset="+charsetName; System.out.println("charsetName = " + charsetName); } catch (IOException e) { e.printStackTrace(); } }