|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.glxp.api.upload;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
|
@ -15,6 +16,7 @@ import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
@ -27,10 +29,13 @@ public class DownloadController {
|
|
|
|
|
, @RequestParam String type
|
|
|
|
|
, @RequestParam String name) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// String filePath = new String(name.getBytes("UTF-8"), "UTF-8");
|
|
|
|
|
if (name.endsWith("pdf") || name.endsWith("doc")) {
|
|
|
|
|
OutputStream os = null;
|
|
|
|
|
try {
|
|
|
|
|
FileInputStream input = new FileInputStream(new File(filePath + "/register/file/" + type + "/" + name));
|
|
|
|
|
File file = new File(filePath + "/register/file/" + type + "/" + name);
|
|
|
|
|
FileInputStream input = new FileInputStream(file);
|
|
|
|
|
OutputStream out = response.getOutputStream();
|
|
|
|
|
byte[] b = new byte[2048];
|
|
|
|
|
int len;
|
|
|
|
@ -39,6 +44,9 @@ public class DownloadController {
|
|
|
|
|
}
|
|
|
|
|
input.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
log.error(e.getMessage());
|
|
|
|
|
log.error(new String(ExceptionUtil.getMessage(e).getBytes(StandardCharsets.UTF_8)));
|
|
|
|
|
log.error("pdf:" + ExceptionUtils.getStackTrace(e));
|
|
|
|
|
} finally {
|
|
|
|
|
if (os != null) {
|
|
|
|
@ -50,8 +58,9 @@ public class DownloadController {
|
|
|
|
|
OutputStream os = null;
|
|
|
|
|
try {
|
|
|
|
|
// 读取图片
|
|
|
|
|
File file = new File(filePath + "/register/file/" + type + "/" + name);
|
|
|
|
|
BufferedImage image = ImageIO.read(
|
|
|
|
|
new FileInputStream(new File(filePath + "/register/file/" + type + "/" + name)));
|
|
|
|
|
new FileInputStream(file));
|
|
|
|
|
response.setContentType("image/png");
|
|
|
|
|
os = response.getOutputStream();
|
|
|
|
|
|
|
|
|
@ -59,6 +68,9 @@ public class DownloadController {
|
|
|
|
|
ImageIO.write(image, "png", os);
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
log.error(e.getMessage());
|
|
|
|
|
log.error(new String(ExceptionUtil.getMessage(e).getBytes(StandardCharsets.UTF_8)));
|
|
|
|
|
log.error("图片:" + ExceptionUtils.getStackTrace(e));
|
|
|
|
|
} finally {
|
|
|
|
|
if (os != null) {
|
|
|
|
@ -85,7 +97,9 @@ public class DownloadController {
|
|
|
|
|
}
|
|
|
|
|
input.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
|
|
log.error(e.getMessage());
|
|
|
|
|
log.error(ExceptionUtil.getMessage(e));
|
|
|
|
|
log.error("图片:" + ExceptionUtils.getStackTrace(e));
|
|
|
|
|
} finally {
|
|
|
|
|
if (os != null) {
|
|
|
|
|
os.flush();
|
|
|
|
@ -110,7 +124,9 @@ public class DownloadController {
|
|
|
|
|
}
|
|
|
|
|
input.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
|
|
log.error(e.getMessage());
|
|
|
|
|
log.error(ExceptionUtil.getMessage(e));
|
|
|
|
|
log.error("图片:" + ExceptionUtils.getStackTrace(e));
|
|
|
|
|
} finally {
|
|
|
|
|
if (os != null) {
|
|
|
|
|
os.flush();
|
|
|
|
|