Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
5a3916c3
Commit
5a3916c3
authored
Sep 10, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口文档的支持
parent
ef029db4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
HttpFileHelper.java
...ain/java/com/yanzuoguang/cloud/helper/HttpFileHelper.java
+8
-2
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/helper/HttpFileHelper.java
View file @
5a3916c3
...
@@ -5,9 +5,11 @@ import com.yanzuoguang.util.helper.HttpHelper;
...
@@ -5,9 +5,11 @@ import com.yanzuoguang.util.helper.HttpHelper;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.io.*
;
import
java.net.URLEncoder
;
/**
/**
* HTTP文件
* HTTP文件
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
HttpFileHelper
extends
HttpHelper
{
public
class
HttpFileHelper
extends
HttpHelper
{
...
@@ -25,8 +27,12 @@ public class HttpFileHelper extends HttpHelper {
...
@@ -25,8 +27,12 @@ public class HttpFileHelper extends HttpHelper {
File
file
=
new
File
(
serverFilePath
);
File
file
=
new
File
(
serverFilePath
);
//设置文件输出类型
//设置文件输出类型
response
.
setContentType
(
"application/octet-stream"
);
response
.
setContentType
(
"application/octet-stream"
);
/**文件下载图片乱码处理**/
String
fileName
=
URLEncoder
.
encode
(
saveFileName
,
"UTF-8"
);
// 设置下载的文件名
// 设置下载的文件名
response
.
setHeader
(
"Content-disposition"
,
"attachment; filename="
+
new
String
(
saveFileName
.
getBytes
(
"utf-8"
),
"UTF-8"
));
// 2.其他浏览器attachment;filename*=utf-8'zh_cn
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename*=utf-8'zh_cn'"
+
fileName
);
//设置输出长度
//设置输出长度
response
.
setHeader
(
"Content-Length"
,
String
.
valueOf
(
file
.
length
()));
response
.
setHeader
(
"Content-Length"
,
String
.
valueOf
(
file
.
length
()));
ServletOutputStream
bos
=
response
.
getOutputStream
();
ServletOutputStream
bos
=
response
.
getOutputStream
();
...
...
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