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
fbd5f40f
Commit
fbd5f40f
authored
Jul 09, 2023
by
chentianzhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下载和预览前判断文件是否能到达
parent
dd2c5cdc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
8 deletions
+21
-8
src/main/java/com/zq/email/controller/EmailAttachController.java
+9
-3
src/main/java/com/zq/email/utils/EmailUtil.java
+12
-5
No files found.
src/main/java/com/zq/email/controller/EmailAttachController.java
View file @
fbd5f40f
...
@@ -4,6 +4,7 @@ package com.zq.email.controller;
...
@@ -4,6 +4,7 @@ package com.zq.email.controller;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.io.file.FileNameUtil
;
import
cn.hutool.core.util.*
;
import
cn.hutool.core.util.*
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.http.HttpUtil
;
...
@@ -79,14 +80,18 @@ public class EmailAttachController {
...
@@ -79,14 +80,18 @@ public class EmailAttachController {
String
download
=
emailAttachService
.
getDownloadPath
(
emailAttach
);
String
download
=
emailAttachService
.
getDownloadPath
(
emailAttach
);
AssertUtils
.
hasText
(
download
,
"下载地址为空"
);
AssertUtils
.
hasText
(
download
,
"下载地址为空"
);
log
.
info
(
"下载文件地址:"
+
download
);
log
.
info
(
"下载文件地址:"
+
download
);
try
{
try
{
byte
[]
bytes
=
HttpUtil
.
downloadBytes
(
download
);
byte
[]
bytes
=
HttpUtil
.
downloadBytes
(
download
);
AssertUtils
.
isTrue
(
ArrayUtil
.
isNotEmpty
(
bytes
),
"下载文件失败,文件为空"
);
AssertUtils
.
isTrue
(
ArrayUtil
.
isNotEmpty
(
bytes
),
"下载文件失败,文件为空"
);
return
ResultVo
.
success
();
return
ResultVo
.
success
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"下载文件失败:"
+
e
.
getLocalizedMessage
(),
e
);
log
.
error
(
"下载文件失败:"
+
e
.
getLocalizedMessage
(),
e
);
return
ResultVo
.
fail
(
"下载文件失败,文件可能不存在"
);
if
(
profile
.
contains
(
"wan"
))
{
return
ResultVo
.
fail
(
"文件可能超过安全时间,禁止从外网访问下载,请从内网查看下载"
);
}
else
{
return
ResultVo
.
fail
(
"下载文件失败,文件可能不存在"
);
}
}
}
}
}
...
@@ -103,7 +108,8 @@ public class EmailAttachController {
...
@@ -103,7 +108,8 @@ public class EmailAttachController {
byte
[]
bytes
=
HttpUtil
.
downloadBytes
(
download
);
byte
[]
bytes
=
HttpUtil
.
downloadBytes
(
download
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename*=UTF-8''"
+
URLEncoder
.
encode
(
emailAttach
.
getAttachName
(),
"UTF-8"
));
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename*=UTF-8''"
+
URLEncoder
.
encode
(
emailAttach
.
getAttachName
(),
"UTF-8"
));
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
ServletUtil
.
write
(
response
,
IoUtil
.
toStream
(
bytes
),
"application/octet-stream"
);
//ServletUtil.write(response, IoUtil.toStream(bytes),"application/octet-stream");
ServletUtil
.
write
(
response
,
IoUtil
.
toStream
(
bytes
),
FileUtil
.
getMimeType
(
emailAttach
.
getAttachName
())!=
null
?
FileUtil
.
getMimeType
(
emailAttach
.
getAttachName
()):
"application/octet-stream"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"下载文件失败:"
+
e
.
getLocalizedMessage
(),
e
);
log
.
error
(
"下载文件失败:"
+
e
.
getLocalizedMessage
(),
e
);
if
(
profile
.
contains
(
"wan"
)){
if
(
profile
.
contains
(
"wan"
)){
...
...
src/main/java/com/zq/email/utils/EmailUtil.java
View file @
fbd5f40f
package
com
.
zq
.
email
.
utils
;
package
com
.
zq
.
email
.
utils
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.io.FileUtil
;
import
com.zq.email.entity.EmailAttach
;
import
com.zq.email.entity.EmailAttach
;
import
io.swagger.models.auth.In
;
import
io.swagger.models.auth.In
;
...
@@ -20,11 +21,15 @@ public class EmailUtil {
...
@@ -20,11 +21,15 @@ public class EmailUtil {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
InternetAddress
[]
parse
=
InternetAddress
.
parse
(
"111@sina.com,111@sina.com,"
);
String
mimeType
=
FileUtil
.
getMimeType
(
"ccccc.ofd"
);
for
(
InternetAddress
internetAddress
:
parse
)
{
System
.
out
.
println
(
mimeType
);
System
.
out
.
println
(
internetAddress
.
toString
());
System
.
out
.
println
(
internetAddress
.
getAddress
());
}
// InternetAddress[] parse = InternetAddress.parse("111@sina.com,111@sina.com,");
// for (InternetAddress internetAddress : parse) {
// System.out.println(internetAddress.toString());
// System.out.println(internetAddress.getAddress());
// }
// Session session = Session.getDefaultInstance(new Properties());
// Session session = Session.getDefaultInstance(new Properties());
// MimeMessage message = createMessage(session);
// MimeMessage message = createMessage(session);
...
@@ -83,4 +88,6 @@ public class EmailUtil {
...
@@ -83,4 +88,6 @@ public class EmailUtil {
}
}
}
}
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