|
@@ -2,22 +2,20 @@ package com.xunwang.file.controller;
|
|
|
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
|
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
|
import com.xunwang.commonutils.R;
|
|
import com.xunwang.commonutils.R;
|
|
|
|
+import io.netty.handler.codec.base64.Base64Encoder;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+import sun.misc.BASE64Encoder;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
+import javax.imageio.stream.FileImageInputStream;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.UUID;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@ApiSupport(author = "Long")
|
|
@ApiSupport(author = "Long")
|
|
@Api("文件相关")
|
|
@Api("文件相关")
|
|
@@ -63,4 +61,31 @@ public class FileUpload {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @ApiOperation("根据路径返回图片base64编码")
|
|
|
|
+ @PostMapping("download")
|
|
|
|
+ public String download(@RequestBody String filePath) {
|
|
|
|
+ byte[] data = null;
|
|
|
|
+ FileImageInputStream input = null;
|
|
|
|
+ String encode = "";
|
|
|
|
+ try {
|
|
|
|
+ input = new FileImageInputStream(new File(filePath));
|
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
+ byte[] buf = new byte[1024];
|
|
|
|
+ int numBytesRead = 0;
|
|
|
|
+ while ((numBytesRead = input.read(buf)) != -1) {
|
|
|
|
+ output.write(buf, 0, numBytesRead);
|
|
|
|
+ }
|
|
|
|
+ data = output.toByteArray();
|
|
|
|
+ output.close();
|
|
|
|
+ input.close();
|
|
|
|
+
|
|
|
|
+ // 将字节数组转为base64
|
|
|
|
+ encode = Base64.encodeBase64String(data).replaceAll("/[\\r\\n]/g", "");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return encode;
|
|
|
|
+ }
|
|
}
|
|
}
|