Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
K
know-base
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
张京坤
know-base
Commits
110f8cd0
提交
110f8cd0
authored
1月 09, 2024
作者:
ZhangJingKun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
文件上传 zhangjingkun
上级
89af4415
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
7 行增加
和
7 行删除
+7
-7
ILocalFileService.java
...ain/java/com/zzsn/knowbase/service/ILocalFileService.java
+2
-2
LocalFileServiceImpl.java
.../com/zzsn/knowbase/service/impl/LocalFileServiceImpl.java
+5
-5
没有找到文件。
src/main/java/com/zzsn/knowbase/service/ILocalFileService.java
浏览文件 @
110f8cd0
package
com
.
zzsn
.
knowbase
.
service
;
package
com
.
zzsn
.
knowbase
.
service
;
import
com.zzsn.knowbase.entity.Know
ledg
e
;
import
com.zzsn.knowbase.entity.Know
Fil
e
;
import
com.zzsn.knowbase.vo.Result
;
import
com.zzsn.knowbase.vo.Result
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -12,5 +12,5 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -12,5 +12,5 @@ import org.springframework.web.multipart.MultipartFile;
*/
*/
public
interface
ILocalFileService
{
public
interface
ILocalFileService
{
Result
<
Know
ledg
e
>
upload
(
MultipartFile
file
,
String
uid
);
Result
<
Know
Fil
e
>
upload
(
MultipartFile
file
,
String
uid
);
}
}
src/main/java/com/zzsn/knowbase/service/impl/LocalFileServiceImpl.java
浏览文件 @
110f8cd0
package
com
.
zzsn
.
knowbase
.
service
.
impl
;
package
com
.
zzsn
.
knowbase
.
service
.
impl
;
import
com.zzsn.knowbase.entity.KnowFile
;
import
com.zzsn.knowbase.entity.KnowFile
;
import
com.zzsn.knowbase.entity.Knowledge
;
import
com.zzsn.knowbase.service.ILocalFileService
;
import
com.zzsn.knowbase.service.ILocalFileService
;
import
com.zzsn.knowbase.util.file.FileUtility
;
import
com.zzsn.knowbase.util.file.FileUtility
;
import
com.zzsn.knowbase.vo.Result
;
import
com.zzsn.knowbase.vo.Result
;
...
@@ -36,13 +35,12 @@ public class LocalFileServiceImpl implements ILocalFileService {
...
@@ -36,13 +35,12 @@ public class LocalFileServiceImpl implements ILocalFileService {
String
filesStorage
;
String
filesStorage
;
@Override
@Override
public
Result
<
Know
ledg
e
>
upload
(
MultipartFile
file
,
String
uid
)
{
public
Result
<
Know
Fil
e
>
upload
(
MultipartFile
file
,
String
uid
)
{
try
{
try
{
String
fullFileName
=
file
.
getOriginalFilename
();
// get file name
String
fullFileName
=
file
.
getOriginalFilename
();
// get file name
String
fileExtension
=
fileUtility
.
getFileExtension
(
fullFileName
);
// get file extension
String
fileExtension
=
fileUtility
.
getFileExtension
(
fullFileName
);
// get file extension
long
fileSize
=
file
.
getSize
();
// get file size
long
fileSize
=
file
.
getSize
();
// get file size
// check if the file size exceeds the maximum file size or is less than 0
// check if the file size exceeds the maximum file size or is less than 0
if
(
fileUtility
.
getMaxFileSize
()
<
fileSize
||
fileSize
<=
0
)
{
if
(
fileUtility
.
getMaxFileSize
()
<
fileSize
||
fileSize
<=
0
)
{
Result
result
=
Result
.
error
(
"文件大小不正确!"
);
Result
result
=
Result
.
error
(
"文件大小不正确!"
);
...
@@ -58,13 +56,15 @@ public class LocalFileServiceImpl implements ILocalFileService {
...
@@ -58,13 +56,15 @@ public class LocalFileServiceImpl implements ILocalFileService {
String
fileName
=
file
.
getOriginalFilename
();
String
fileName
=
file
.
getOriginalFilename
();
String
fileSuffix
=
getFileSuffix
(
fileName
);
String
fileSuffix
=
getFileSuffix
(
fileName
);
String
filePath
=
getFilePath
()
+
UUID
.
randomUUID
();
uid
=
UUID
.
randomUUID
().
toString
();
String
filePath
=
getFilePath
()
+
uid
;
byte
[]
bytes
=
file
.
getBytes
();
// get file in bytes
byte
[]
bytes
=
file
.
getBytes
();
// get file in bytes
//Files.write(Paths.get(filePath), bytes);
//Files.write(Paths.get(filePath), bytes);
file
.
transferTo
(
new
File
(
filePath
));
file
.
transferTo
(
new
File
(
filePath
));
KnowFile
knowFile
=
new
KnowFile
();
KnowFile
knowFile
=
new
KnowFile
();
knowFile
.
setFileId
(
fileName
);
knowFile
.
setFileId
(
uid
);
knowFile
.
setFileName
(
fileName
);
knowFile
.
setFileName
(
fileName
);
knowFile
.
setFilePath
(
filePath
);
knowFile
.
setFilePath
(
filePath
);
knowFile
.
setFileType
(
fileSuffix
);
knowFile
.
setFileType
(
fileSuffix
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论