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
0d61c378
Commit
0d61c378
authored
Jul 05, 2023
by
chentianzhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2023年7月5日21:20:24
parent
2348d5ec
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletions
+34
-1
src/main/java/com/zq/email/controller/EmailAttachController.java
+33
-0
src/main/resources/logback-spring.xml
+1
-1
No files found.
src/main/java/com/zq/email/controller/EmailAttachController.java
View file @
0d61c378
...
@@ -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
,
"网络异常,下载文件失败"
);
...
...
src/main/resources/logback-spring.xml
View file @
0d61c378
...
@@ -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/"/>-->
<!--主要日志文件名-->
<!--主要日志文件名-->
...
...
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