Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
email
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈天仲
email
Commits
3fa5bf89
Commit
3fa5bf89
authored
Jul 07, 2023
by
chentianzhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下载
parent
0d61c378
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
20 deletions
+15
-20
src/main/java/com/zq/email/controller/EmailAttachController.java
+15
-20
No files found.
src/main/java/com/zq/email/controller/EmailAttachController.java
View file @
3fa5bf89
...
...
@@ -4,9 +4,7 @@ package com.zq.email.controller;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.*
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONUtil
;
...
...
@@ -38,6 +36,7 @@ import java.io.ByteArrayOutputStream;
import
java.io.File
;
import
java.io.OutputStream
;
import
java.net.URLEncoder
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -59,6 +58,8 @@ public class EmailAttachController {
private
final
IEmailAttachService
emailAttachService
;
private
final
FileFeignClient
fileFeignClient
;
@Value
(
"${spring.cloud.config.profile}"
)
private
String
profile
;
@ApiOperation
(
"获取附件"
)
...
...
@@ -68,7 +69,7 @@ public class EmailAttachController {
return
ResultVo
.
success
(
emailAttachService
.
findByContentId
(
vo
.
getContentId
()));
}
@ApiOperation
(
"
下载附件
"
)
@ApiOperation
(
"
pc统一下载附件和移动端旧附件下载
"
)
@AnonymousGetMapping
(
"/download/{id}"
)
public
void
download
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@PathVariable
(
"id"
)
Long
id
)
{
EmailAttach
emailAttach
=
emailAttachService
.
getById
(
id
);
...
...
@@ -81,27 +82,17 @@ public class EmailAttachController {
try
{
HttpUtil
.
download
(
download
,
outputStream
,
true
);
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"
,
new
String
(
emailAttach
.
getAttachName
().
getBytes
(
StandardCharsets
.
UTF_8
),
StandardCharsets
.
ISO_8859_1
));
// ServletUtil.write(response, IoUtil.toStream(bytes), "application/octet-stream",
// emailAttach.getAttachName());
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename*=UTF-8''"
+
URLEncoder
.
encode
(
emailAttach
.
getAttachName
(),
"UTF-8"
));
response
.
setCharacterEncoding
(
"UTF-8"
);
ServletUtil
.
write
(
response
,
IoUtil
.
toStream
(
bytes
),
"application/octet-stream"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"下载文件失败:"
+
e
.
getLocalizedMessage
(),
e
);
AssertUtils
.
isTrue
(
false
,
"
网络异常,下载文件失败
"
);
AssertUtils
.
isTrue
(
false
,
"
下载文件失败,文件可能不存在
"
);
}
}
@ApiOperation
(
"下载附件"
)
@ApiOperation
(
"移动办公新OA邮件下载附件"
)
@AnonymousGetMapping
(
"/download2/{id}/{filename}"
)
public
void
downloadFile
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@PathVariable
(
"id"
)
Long
id
,
@PathVariable
(
"filename"
)
String
filename
)
{
EmailAttach
emailAttach
=
emailAttachService
.
getById
(
id
);
...
...
@@ -117,7 +108,11 @@ public class EmailAttachController {
ServletUtil
.
write
(
response
,
IoUtil
.
toStream
(
bytes
),
"application/octet-stream"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"下载文件失败:"
+
e
.
getLocalizedMessage
(),
e
);
AssertUtils
.
isTrue
(
false
,
"网络异常,下载文件失败"
);
if
(
profile
.
contains
(
"wan"
)){
AssertUtils
.
isTrue
(
false
,
"文件超过安全时间,禁止从外网访问"
);
}
else
{
AssertUtils
.
isTrue
(
false
,
"下载文件失败,文件可能不存在"
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment