|
|
@@ -3,6 +3,8 @@ package com.xunmei.file.service;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.ArrayUtil;
|
|
|
+import cn.hutool.core.util.ByteUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
@@ -33,6 +35,7 @@ import com.xunmei.system.api.domain.SafeCheckTaskRegisterBookVo;
|
|
|
import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import io.netty.util.internal.StringUtil;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.text.StringEscapeUtils;
|
|
|
import org.apache.tools.zip.ZipEntry;
|
|
|
@@ -941,7 +944,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void readFile(String path, HttpServletResponse response) throws IOException {
|
|
|
+ public byte[] readFile(String path) throws IOException {
|
|
|
if (ObjectUtil.isEmpty(path)) {
|
|
|
throw new RuntimeException("文件地址无效");
|
|
|
}
|
|
|
@@ -953,15 +956,29 @@ public class LocalSysFileServiceImpl implements ISysFileService {
|
|
|
conn.setRequestMethod("GET");
|
|
|
conn.setConnectTimeout(5 * 1000);
|
|
|
InputStream stream = conn.getInputStream();
|
|
|
+// FileUtil.del("d:\\1111.jpg");
|
|
|
+//FileUtil.writeFromStream(stream,"d:\\1111.jpg");
|
|
|
+
|
|
|
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
|
|
try (BufferedInputStream bis = new BufferedInputStream(stream)) {
|
|
|
// 设置响应类型
|
|
|
- response.setContentType("image/*");
|
|
|
- response.setHeader("Content-Length", String.valueOf(stream.available()));
|
|
|
+// response.setContentType("image/*");
|
|
|
+// response.setHeader("Content-Length", String.valueOf(stream.available()));
|
|
|
// 将文件流发送给前端
|
|
|
byte[] buffer = new byte[1024];
|
|
|
int bytesRead;
|
|
|
while ((bytesRead = bis.read(buffer)) != -1) {
|
|
|
- response.getOutputStream().write(buffer, 0, bytesRead);
|
|
|
+ outStream.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+
|
|
|
+ byte[] r = outStream.toByteArray();
|
|
|
+ if (r[0] == 10) {
|
|
|
+ byte[] r1 = new byte[r.length - 1];
|
|
|
+
|
|
|
+ ArrayUtil.copy(r, 1, r1, 0, r1.length);
|
|
|
+ return r1;
|
|
|
+ } else {
|
|
|
+ return r;
|
|
|
}
|
|
|
}
|
|
|
}
|