Commit 7cc61755 by 汪鑫

图片压缩代码修正

parent 27b63f75
...@@ -77,6 +77,23 @@ public class CommonController extends BaseController { ...@@ -77,6 +77,23 @@ public class CommonController extends BaseController {
@ApiOperation("图片转base64") @ApiOperation("图片转base64")
@PostMapping("imageToBase64") @PostMapping("imageToBase64")
public RespInfo<String> imageToBase64(MultipartFile file) throws IOException { public RespInfo<String> imageToBase64(MultipartFile file) throws IOException {
// if (file.getSize()/1024 > 10){
// File tempFile = new File("temp/"+file.getOriginalFilename().substring(0,file.getOriginalFilename().indexOf("."))+"(1)"+file.getOriginalFilename().indexOf("."));
// FileWriter writer = FileWriter.create(tempFile);
// writer.writeFromStream(file.getInputStream());
// File newFile = new File("temp/" + file.getOriginalFilename());
// ImgUtil.compress(tempFile,newFile,0.5F);
// FileInputStream fileInputStream = null;
// try {
// fileInputStream = new FileInputStream(newFile);
// file = new MockMultipartFile(newFile.getName(),newFile.getName(),
// ContentType.APPLICATION_OCTET_STREAM.toString(),fileInputStream);
// } catch (Exception e) {
// e.printStackTrace();
// }
// FileUtil.del(tempFile);
// FileUtil.del(newFile);
// }
String baseStr = null; String baseStr = null;
BASE64Encoder encoder = new BASE64Encoder(); BASE64Encoder encoder = new BASE64Encoder();
baseStr= encoder.encode(file.getBytes()); baseStr= encoder.encode(file.getBytes());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment