Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
仟微科技
Link Wechat
提交
ae70522d
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,体验更适合开发者的 AI 搜索 >>
提交
ae70522d
编写于
6月 08, 2021
作者:
水
水库浪子
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化文件上传接口,文件上传同时支持本地上传与腾讯云上传
上级
3c98c717
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
60 addition
and
10 deletion
+60
-10
linkwe-admin/src/main/java/com/linkwechat/web/controller/common/CommonController.java
...om/linkwechat/web/controller/common/CommonController.java
+2
-2
linkwe-common/src/main/java/com/linkwechat/common/config/FileConfig.java
...rc/main/java/com/linkwechat/common/config/FileConfig.java
+1
-1
linkwe-common/src/main/java/com/linkwechat/common/utils/ImageCheckUtils.java
...ain/java/com/linkwechat/common/utils/ImageCheckUtils.java
+27
-0
linkwe-common/src/main/java/com/linkwechat/common/utils/file/FileUploadUtils.java
...ava/com/linkwechat/common/utils/file/FileUploadUtils.java
+4
-2
linkwe-common/src/main/java/com/linkwechat/common/utils/file/FileUtils.java
...main/java/com/linkwechat/common/utils/file/FileUtils.java
+3
-0
linkwe-framework/src/main/java/com/linkwechat/framework/web/service/FileService.java
...ava/com/linkwechat/framework/web/service/FileService.java
+23
-5
未找到文件。
linkwe-admin/src/main/java/com/linkwechat/web/controller/common/CommonController.java
浏览文件 @
ae70522d
...
@@ -124,7 +124,7 @@ public class CommonController {
...
@@ -124,7 +124,7 @@ public class CommonController {
=
fileService
.
upload
(
file
);
=
fileService
.
upload
(
file
);
AjaxResult
ajax
=
AjaxResult
.
success
();
AjaxResult
ajax
=
AjaxResult
.
success
();
ajax
.
put
(
"fileName"
,
sysFile
.
getFileName
());
ajax
.
put
(
"fileName"
,
sysFile
.
getFileName
());
ajax
.
put
(
"url"
,
sysFile
.
getImgUrlPrefix
()
+
sysFile
.
getFileName
()
);
ajax
.
put
(
"url"
,
sysFile
.
getImgUrlPrefix
());
return
ajax
;
return
ajax
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
AjaxResult
.
error
(
e
.
getMessage
());
return
AjaxResult
.
error
(
e
.
getMessage
());
...
@@ -135,7 +135,7 @@ public class CommonController {
...
@@ -135,7 +135,7 @@ public class CommonController {
/**
/**
* 本地图片下载
* 本地图片下载
*/
*/
@GetMapping
(
"/findFile"
)
@GetMapping
(
"/
common/
findFile"
)
public
void
findFile
(
HttpServletResponse
response
,
String
fileName
){
public
void
findFile
(
HttpServletResponse
response
,
String
fileName
){
fileService
.
findFile
(
fileName
,
response
);
fileService
.
findFile
(
fileName
,
response
);
}
}
...
...
linkwe-common/src/main/java/com/linkwechat/common/config/FileConfig.java
浏览文件 @
ae70522d
...
@@ -10,5 +10,5 @@ public class FileConfig {
...
@@ -10,5 +10,5 @@ public class FileConfig {
/**腾讯云存储相关配置*/
/**腾讯云存储相关配置*/
private
CosConfig
cos
;
private
CosConfig
cos
;
/**文件前缀*/
/**文件前缀*/
private
String
imgUrlPrefix
;
private
String
imgUrlPrefix
=
"/common/findFile?fileName="
;
}
}
linkwe-common/src/main/java/com/linkwechat/common/utils/ImageCheckUtils.java
0 → 100644
浏览文件 @
ae70522d
package
com.linkwechat.common.utils
;
import
javax.activation.MimetypesFileTypeMap
;
import
java.io.File
;
/**
* @description:
* @author: HaoN
* @create: 2021-06-08 15:27
**/
public
class
ImageCheckUtils
{
private
static
MimetypesFileTypeMap
mtftp
;
static
{
mtftp
=
new
MimetypesFileTypeMap
();
/* 不添加下面的类型会造成误判 详见:http://stackoverflow.com/questions/4855627/java-mimetypesfiletypemap-always-returning-application-octet-stream-on-android-e*/
mtftp
.
addMimeTypes
(
"image png tif jpg jpeg bmp"
);
}
public
static
boolean
isImage
(
File
file
){
String
mimetype
=
mtftp
.
getContentType
(
file
);
String
type
=
mimetype
.
split
(
"/"
)[
0
];
return
type
.
equals
(
"image"
);
}
}
linkwe-common/src/main/java/com/linkwechat/common/utils/file/FileUploadUtils.java
浏览文件 @
ae70522d
...
@@ -275,9 +275,11 @@ public class FileUploadUtils {
...
@@ -275,9 +275,11 @@ public class FileUploadUtils {
String
currentDir
=
StringUtils
.
substring
(
uploadDir
,
dirLastIndex
);
String
currentDir
=
StringUtils
.
substring
(
uploadDir
,
dirLastIndex
);
String
pathFileName
;
String
pathFileName
;
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isBlank
(
currentDir
)){
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isBlank
(
currentDir
)){
pathFileName
=
Constants
.
RESOURCE_PREFIX
+
"/"
+
fileName
;
// pathFileName = Constants.RESOURCE_PREFIX + "/" +fileName;
pathFileName
=
"/"
+
fileName
;
}
else
{
}
else
{
pathFileName
=
Constants
.
RESOURCE_PREFIX
+
"/"
+
currentDir
+
"/"
+
fileName
;
// pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
pathFileName
=
"/"
+
currentDir
+
"/"
+
fileName
;
}
}
return
pathFileName
;
return
pathFileName
;
}
}
...
...
linkwe-common/src/main/java/com/linkwechat/common/utils/file/FileUtils.java
浏览文件 @
ae70522d
...
@@ -203,4 +203,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils
...
@@ -203,4 +203,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils
}
}
return
filename
;
return
filename
;
}
}
}
}
linkwe-framework/src/main/java/com/linkwechat/framework/web/service/FileService.java
浏览文件 @
ae70522d
...
@@ -2,13 +2,16 @@ package com.linkwechat.framework.web.service;
...
@@ -2,13 +2,16 @@ package com.linkwechat.framework.web.service;
import
com.linkwechat.common.config.RuoYiConfig
;
import
com.linkwechat.common.config.RuoYiConfig
;
import
com.linkwechat.common.utils.ImageCheckUtils
;
import
com.linkwechat.common.utils.OsUtils
;
import
com.linkwechat.common.utils.OsUtils
;
import
com.linkwechat.common.utils.file.FileUploadUtils
;
import
com.linkwechat.common.utils.file.FileUploadUtils
;
import
com.linkwechat.framework.web.domain.server.Sys
;
import
com.linkwechat.framework.web.domain.server.SysFile
;
import
com.linkwechat.framework.web.domain.server.SysFile
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.imageio.ImageIO
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
...
@@ -54,7 +57,7 @@ public class FileService {
...
@@ -54,7 +57,7 @@ public class FileService {
}
}
return
SysFile
.
builder
()
return
SysFile
.
builder
()
.
fileName
(
fileName
)
.
fileName
(
fileName
)
.
imgUrlPrefix
(
ruoYiConfig
.
getFile
().
getImgUrlPrefix
())
.
imgUrlPrefix
(
ruoYiConfig
.
getFile
().
getImgUrlPrefix
()
+
fileName
)
.
build
();
.
build
();
}
}
...
@@ -62,13 +65,28 @@ public class FileService {
...
@@ -62,13 +65,28 @@ public class FileService {
public
void
findFile
(
String
fileName
,
HttpServletResponse
rp
){
public
void
findFile
(
String
fileName
,
HttpServletResponse
rp
){
String
fileDownUrl
=
""
;
String
fileDownUrl
=
""
;
// if(ruoYiConfig.getFile().isStartCosUpload()) {//开启云上传
// fileDownUrl= ruoYiConfig.getFile().getImgUrlPrefix();
// }else{
if
(
ruoYiConfig
.
getFile
().
isStartCosUpload
())
{
//开启云上传
fileDownUrl
=
ruoYiConfig
.
getFile
().
getImgUrlPrefix
();
}
else
{
fileDownUrl
=
OsUtils
.
isWindows
()?
WINDOWSFILEPATH
+
fileName:
LINUXFILEPATH
+
fileName
;
fileDownUrl
=
OsUtils
.
isWindows
()?
WINDOWSFILEPATH
+
fileName:
LINUXFILEPATH
+
fileName
;
// }
}
File
file
=
new
File
(
fileDownUrl
);
File
file
=
new
File
(
fileDownUrl
);
if
(
file
.
exists
())
{
if
(
file
.
exists
())
{
if
(
ImageCheckUtils
.
isImage
(
file
)){
rp
.
setContentType
(
"image/png"
);
}
else
{
rp
.
setCharacterEncoding
(
"utf-8"
);
rp
.
setContentType
(
"multipart/form-data"
);
rp
.
setHeader
(
"Content-Disposition"
,
"attachment;fileName="
+
fileName
.
substring
(
fileName
.
lastIndexOf
(
"/"
)+
1
));
}
FileInputStream
fis
=
null
;
FileInputStream
fis
=
null
;
OutputStream
os
=
null
;
OutputStream
os
=
null
;
try
{
try
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录