Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
仟微科技
Link Wechat
提交
a102c340
Link Wechat
项目概览
仟微科技
/
Link Wechat
通知
48
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Link Wechat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a102c340
编写于
5月 20, 2021
作者:
水
水库浪子
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
文件下载相关代码提交;
上级
36429072
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
11 deletion
+51
-11
linkwe-admin/src/main/java/com/linkwechat/web/controller/common/CommonController.java
...om/linkwechat/web/controller/common/CommonController.java
+11
-10
linkwe-framework/src/main/java/com/linkwechat/framework/web/service/FileService.java
...ava/com/linkwechat/framework/web/service/FileService.java
+40
-1
未找到文件。
linkwe-admin/src/main/java/com/linkwechat/web/controller/common/CommonController.java
浏览文件 @
a102c340
...
...
@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -33,9 +34,6 @@ public class CommonController {
@Autowired
private
ServerConfig
serverConfig
;
@Autowired
private
CosConfig
cosConfig
;
@Autowired
private
FileService
fileService
;
...
...
@@ -122,12 +120,8 @@ public class CommonController {
@PostMapping
(
"/common/uploadFile2Cos"
)
public
AjaxResult
uploadFile2Cos
(
MultipartFile
file
)
throws
Exception
{
try
{
SysFile
sysFile
=
fileService
.
upload
(
file
);
// String fileName = FileUploadUtils.upload2Cos(file, cosConfig);
AjaxResult
ajax
=
AjaxResult
.
success
();
ajax
.
put
(
"fileName"
,
sysFile
.
getFileName
());
ajax
.
put
(
"url"
,
sysFile
.
getImgUrlPrefix
()+
sysFile
.
getFileName
());
...
...
@@ -138,8 +132,15 @@ public class CommonController {
}
// public String url(String fileName){
// return "https://link-wechat-1251309172.cos.ap-nanjing.myqcloud.com/"+fileName;
// }
/**
* 本地图片下载
*/
@GetMapping
(
"/findFile"
)
public
void
findFile
(
HttpServletResponse
response
,
String
fileName
){
fileService
.
findFile
(
fileName
,
response
);
}
}
linkwe-framework/src/main/java/com/linkwechat/framework/web/service/FileService.java
浏览文件 @
a102c340
...
...
@@ -9,8 +9,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
/**
...
...
@@ -37,7 +40,7 @@ public class FileService {
* @return
* @throws IOException
*/
public
SysFile
upload
(
MultipartFile
file
)
throws
IOException
{
public
SysFile
upload
(
MultipartFile
file
)
throws
IOException
{
String
fileName
=
""
;
if
(
ruoYiConfig
.
getFile
().
isStartCosUpload
()){
//开启云上传
//开启云上传开关则云上传,不然上传本地
...
...
@@ -56,4 +59,40 @@ public class FileService {
}
public
void
findFile
(
String
fileName
,
HttpServletResponse
rp
){
String
fileDownUrl
=
""
;
// if(ruoYiConfig.getFile().isStartCosUpload()) {//开启云上传
// fileDownUrl= ruoYiConfig.getFile().getImgUrlPrefix();
// }else{
fileDownUrl
=
OsUtils
.
isWindows
()?
WINDOWSFILEPATH
+
fileName:
LINUXFILEPATH
+
fileName
;
// }
File
file
=
new
File
(
fileDownUrl
);
if
(
file
.
exists
())
{
FileInputStream
fis
=
null
;
OutputStream
os
=
null
;
try
{
fis
=
new
FileInputStream
(
file
);
os
=
rp
.
getOutputStream
();
int
count
=
0
;
byte
[]
buffer
=
new
byte
[
1024
*
8
];
while
((
count
=
fis
.
read
(
buffer
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
count
);
os
.
flush
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
fis
.
close
();
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录