Commit 0d61c378 by chentianzhong

2023年7月5日21:20:24

parent 2348d5ec
...@@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -80,8 +81,40 @@ public class EmailAttachController { ...@@ -80,8 +81,40 @@ public class EmailAttachController {
try { try {
HttpUtil.download(download, outputStream, true); HttpUtil.download(download, outputStream, true);
byte[] bytes = outputStream.toByteArray(); byte[] bytes = outputStream.toByteArray();
// String filename = URLEncoder.encode(emailAttach.getAttachName(),"UTF-8");
// response.setHeader("Content-disposition", "attachment;filename="+filename+";"+"filename*=utf-8''"+filename);
// ServletUtil.write(response, IoUtil.toStream(bytes), "application/octet-stream");
ServletUtil.write(response, IoUtil.toStream(bytes), "application/octet-stream", ServletUtil.write(response, IoUtil.toStream(bytes), "application/octet-stream",
new String(emailAttach.getAttachName().getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1)); new String(emailAttach.getAttachName().getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
// ServletUtil.write(response, IoUtil.toStream(bytes), "application/octet-stream",
// emailAttach.getAttachName());
} catch (Exception e) {
log.error("下载文件失败:" + e.getLocalizedMessage(), e);
AssertUtils.isTrue(false, "网络异常,下载文件失败");
}
}
@ApiOperation("下载附件")
@AnonymousGetMapping("/download2/{id}/{filename}")
public void downloadFile(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id, @PathVariable("filename") String filename) {
EmailAttach emailAttach = emailAttachService.getById(id);
AssertUtils.notNull(emailAttach, "获取附件信息失败");
String download = emailAttachService.getDownloadPath(emailAttach);
AssertUtils.hasText(download, "下载地址为空");
log.info("下载文件地址:" +download);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
HttpUtil.download(download, outputStream, true);
byte[] bytes = outputStream.toByteArray();
ServletUtil.write(response, IoUtil.toStream(bytes), "application/octet-stream");
} catch (Exception e) { } catch (Exception e) {
log.error("下载文件失败:" + e.getLocalizedMessage(), e); log.error("下载文件失败:" + e.getLocalizedMessage(), e);
AssertUtils.isTrue(false, "网络异常,下载文件失败"); AssertUtils.isTrue(false, "网络异常,下载文件失败");
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<contextName>logback</contextName> <contextName>logback</contextName>
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 --> <!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
<!-- <property name="log.path" value="/opt/oa-cloud/email/logs/"/>--> <!-- <property name="log.path" value="/opt/oa-cloud/email/logs/"/>-->
<property name="log.path" value="/opt/services/oa/email/logs/"/> <property name="log.path" value="/opt/services/email/logs/"/>
<!-- <property name="log.path" value="D:/seallog/"/>--> <!-- <property name="log.path" value="D:/seallog/"/>-->
<!--主要日志文件名--> <!--主要日志文件名-->
......
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