Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
fec84f26
提交
fec84f26
authored
7月 08, 2022
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
基于 tika 识别文件类型
上级
33e5c2a7
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
45 行增加
和
4 行删除
+45
-4
pom.xml
yudao-dependencies/pom.xml
+7
-0
pom.xml
yudao-framework/yudao-spring-boot-starter-file/pom.xml
+5
-0
FileTypeUtils.java
...ocoder/yudao/framework/file/core/utils/FileTypeUtils.java
+29
-0
FileServiceImpl.java
...oder/yudao/module/infra/service/file/FileServiceImpl.java
+4
-4
没有找到文件。
yudao-dependencies/pom.xml
浏览文件 @
fec84f26
...
@@ -63,6 +63,7 @@
...
@@ -63,6 +63,7 @@
<transmittable-thread-local.version>
2.12.2
</transmittable-thread-local.version>
<transmittable-thread-local.version>
2.12.2
</transmittable-thread-local.version>
<commons-net.version>
3.8.0
</commons-net.version>
<commons-net.version>
3.8.0
</commons-net.version>
<jsch.version>
0.1.55
</jsch.version>
<jsch.version>
0.1.55
</jsch.version>
<tika-core.version>
2.4.1
</tika-core.version>
<!-- 三方云服务相关 -->
<!-- 三方云服务相关 -->
<minio.version>
8.2.2
</minio.version>
<minio.version>
8.2.2
</minio.version>
<aliyun-java-sdk-core.version>
4.5.25
</aliyun-java-sdk-core.version>
<aliyun-java-sdk-core.version>
4.5.25
</aliyun-java-sdk-core.version>
...
@@ -523,6 +524,12 @@
...
@@ -523,6 +524,12 @@
<version>
${easyexcel.verion}
</version>
<version>
${easyexcel.verion}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.tika
</groupId>
<artifactId>
tika-core
</artifactId>
<!-- 文件类型的识别 -->
<version>
${tika-core.version}
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.velocity
</groupId>
<groupId>
org.apache.velocity
</groupId>
<artifactId>
velocity-engine-core
</artifactId>
<artifactId>
velocity-engine-core
</artifactId>
...
...
yudao-framework/yudao-spring-boot-starter-file/pom.xml
浏览文件 @
fec84f26
...
@@ -61,6 +61,11 @@
...
@@ -61,6 +61,11 @@
<artifactId>
jsch
</artifactId>
<!-- 解决 sftp 连接 -->
<artifactId>
jsch
</artifactId>
<!-- 解决 sftp 连接 -->
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.tika
</groupId>
<artifactId>
tika-core
</artifactId>
<!-- 文件类型的识别 -->
</dependency>
<!-- 三方云服务相关 -->
<!-- 三方云服务相关 -->
<dependency>
<dependency>
<groupId>
io.minio
</groupId>
<groupId>
io.minio
</groupId>
...
...
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/utils/FileTypeUtils.java
0 → 100644
浏览文件 @
fec84f26
package
cn
.
iocoder
.
yudao
.
framework
.
file
.
core
.
utils
;
import
com.alibaba.ttl.TransmittableThreadLocal
;
import
lombok.SneakyThrows
;
import
org.apache.tika.Tika
;
import
java.io.ByteArrayInputStream
;
/**
* 文件类型 Utils
*
* @author 芋道源码
*/
public
class
FileTypeUtils
{
private
static
final
ThreadLocal
<
Tika
>
TIKA
=
TransmittableThreadLocal
.
withInitial
(
Tika:
:
new
);
/**
* 获得文件的 mineType
*
* @param data 文件内容
* @return mineType
*/
@SneakyThrows
public
static
String
getMineType
(
byte
[]
data
)
{
return
TIKA
.
get
().
detect
(
new
ByteArrayInputStream
(
data
));
}
}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
浏览文件 @
fec84f26
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
service
.
file
;
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
service
.
file
;
import
cn.hutool.core.io.FileTypeUtil
;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.crypto.digest.DigestUtil
;
import
cn.hutool.crypto.digest.DigestUtil
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.framework.file.core.client.FileClient
;
import
cn.iocoder.yudao.framework.file.core.client.FileClient
;
import
cn.iocoder.yudao.framework.file.core.utils.FileTypeUtils
;
import
cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO
;
import
cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO
;
import
cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO
;
import
cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO
;
import
cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper
;
import
cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper
;
...
@@ -13,7 +13,6 @@ import lombok.SneakyThrows;
...
@@ -13,7 +13,6 @@ import lombok.SneakyThrows;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.ByteArrayInputStream
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
exception
.
util
.
ServiceExceptionUtil
.
exception
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
exception
.
util
.
ServiceExceptionUtil
.
exception
;
import
static
cn
.
iocoder
.
yudao
.
module
.
infra
.
enums
.
ErrorCodeConstants
.
FILE_NOT_EXISTS
;
import
static
cn
.
iocoder
.
yudao
.
module
.
infra
.
enums
.
ErrorCodeConstants
.
FILE_NOT_EXISTS
;
...
@@ -41,9 +40,10 @@ public class FileServiceImpl implements FileService {
...
@@ -41,9 +40,10 @@ public class FileServiceImpl implements FileService {
@SneakyThrows
@SneakyThrows
public
String
createFile
(
String
name
,
String
path
,
byte
[]
content
)
{
public
String
createFile
(
String
name
,
String
path
,
byte
[]
content
)
{
// 计算默认的 path 名
// 计算默认的 path 名
String
type
=
FileTypeUtil
.
getType
(
new
ByteArrayInputStream
(
content
),
name
);
String
type
=
FileTypeUtil
s
.
getMineType
(
content
);
if
(
StrUtil
.
isEmpty
(
path
))
{
if
(
StrUtil
.
isEmpty
(
path
))
{
path
=
DigestUtil
.
md5Hex
(
content
)
+
'.'
+
type
;
path
=
DigestUtil
.
md5Hex
(
content
)
+
'.'
+
StrUtil
.
subAfter
(
type
,
'/'
,
true
);
// 文件的后缀
}
}
// 如果 name 为空,则使用 path 填充
// 如果 name 为空,则使用 path 填充
if
(
StrUtil
.
isEmpty
(
name
))
{
if
(
StrUtil
.
isEmpty
(
name
))
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论