Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
5f8c569a
提交
5f8c569a
authored
11月 29, 2022
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
!313 修复上传七牛云无mime type问题
上级
583cb938
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
17 行增加
和
17 行删除
+17
-17
FileClient.java
.../iocoder/yudao/framework/file/core/client/FileClient.java
+1
-1
DBFileClient.java
...der/yudao/framework/file/core/client/db/DBFileClient.java
+1
-1
FtpFileClient.java
...r/yudao/framework/file/core/client/ftp/FtpFileClient.java
+1
-2
LocalFileClient.java
...dao/framework/file/core/client/local/LocalFileClient.java
+1
-1
S3FileClient.java
...der/yudao/framework/file/core/client/s3/S3FileClient.java
+2
-1
SftpFileClient.java
...yudao/framework/file/core/client/sftp/SftpFileClient.java
+1
-1
FileTypeUtils.java
...ocoder/yudao/framework/file/core/utils/FileTypeUtils.java
+2
-2
FtpFileClientTest.java
...dao/framework/file/core/client/ftp/FtpFileClientTest.java
+1
-1
LocalFileClientTest.java
...framework/file/core/client/local/LocalFileClientTest.java
+1
-1
S3FileClientTest.java
...yudao/framework/file/core/client/s3/S3FileClientTest.java
+1
-1
SftpFileClientTest.java
...o/framework/file/core/client/sftp/SftpFileClientTest.java
+1
-1
FileConfigServiceImpl.java
...udao/module/infra/service/file/FileConfigServiceImpl.java
+3
-3
FileServiceImpl.java
...oder/yudao/module/infra/service/file/FileServiceImpl.java
+1
-1
没有找到文件。
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/FileClient.java
浏览文件 @
5f8c569a
...
...
@@ -22,7 +22,7 @@ public interface FileClient {
* @return 完整路径,即 HTTP 访问地址
* @throws Exception 上传文件时,抛出 Exception 异常
*/
String
upload
(
byte
[]
content
,
String
path
)
throws
Exception
;
String
upload
(
byte
[]
content
,
String
path
,
String
type
)
throws
Exception
;
/**
* 删除文件
...
...
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/db/DBFileClient.java
浏览文件 @
5f8c569a
...
...
@@ -21,7 +21,7 @@ public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
}
@Override
public
String
upload
(
byte
[]
content
,
String
path
)
{
public
String
upload
(
byte
[]
content
,
String
path
,
String
type
)
{
getDao
().
insert
(
getId
(),
path
,
content
);
// 拼接返回路径
return
super
.
formatFileUrl
(
config
.
getDomain
(),
path
);
...
...
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClient.java
浏览文件 @
5f8c569a
...
...
@@ -10,7 +10,6 @@ import cn.iocoder.yudao.framework.file.core.client.AbstractFileClient;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
/**
* Ftp 文件客户端
...
...
@@ -39,7 +38,7 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
}
@Override
public
String
upload
(
byte
[]
content
,
String
path
)
{
public
String
upload
(
byte
[]
content
,
String
path
,
String
type
)
{
// 执行写入
String
filePath
=
getFilePath
(
path
);
String
fileName
=
FileUtil
.
getName
(
filePath
);
...
...
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClient.java
浏览文件 @
5f8c569a
...
...
@@ -25,7 +25,7 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
}
@Override
public
String
upload
(
byte
[]
content
,
String
path
)
{
public
String
upload
(
byte
[]
content
,
String
path
,
String
type
)
{
// 执行写入
String
filePath
=
getFilePath
(
path
);
FileUtil
.
writeBytes
(
content
,
filePath
);
...
...
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClient.java
浏览文件 @
5f8c569a
...
...
@@ -82,10 +82,11 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
}
@Override
public
String
upload
(
byte
[]
content
,
String
path
)
throws
Exception
{
public
String
upload
(
byte
[]
content
,
String
path
,
String
type
)
throws
Exception
{
// 执行上传
client
.
putObject
(
PutObjectArgs
.
builder
()
.
bucket
(
config
.
getBucket
())
// bucket 必须传递
.
contentType
(
type
)
.
object
(
path
)
// 相对路径作为 key
.
stream
(
new
ByteArrayInputStream
(
content
),
content
.
length
,
-
1
)
// 文件内容
.
build
());
...
...
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClient.java
浏览文件 @
5f8c569a
...
...
@@ -31,7 +31,7 @@ public class SftpFileClient extends AbstractFileClient<SftpFileClientConfig> {
}
@Override
public
String
upload
(
byte
[]
content
,
String
path
)
{
public
String
upload
(
byte
[]
content
,
String
path
,
String
type
)
{
// 执行写入
String
filePath
=
getFilePath
(
path
);
File
file
=
FileUtils
.
createTempFile
(
content
);
...
...
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/utils/FileTypeUtils.java
浏览文件 @
5f8c569a
...
...
@@ -16,7 +16,7 @@ public class FileTypeUtils {
/**
* 获得文件的 mineType,对于doc,jar等文件会有误差
*
* @param data
包含文件开头几千个字节的字节数组
* @param data
文件内容
* @return mineType 无法识别时会返回“application/octet-stream”
*/
@SneakyThrows
...
...
@@ -37,7 +37,7 @@ public class FileTypeUtils {
/**
* 在拥有文件和数据的情况下,最好使用此方法,最为准确
*
* @param data
包含文件开头几千个字节的字节数组
* @param data
文件内容
* @param name 文件名
* @return mineType 无法识别时会返回“application/octet-stream”
*/
...
...
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/ftp/FtpFileClientTest.java
浏览文件 @
5f8c569a
...
...
@@ -25,7 +25,7 @@ public class FtpFileClientTest {
// 上传文件
String
path
=
IdUtil
.
fastSimpleUUID
()
+
".jpg"
;
byte
[]
content
=
ResourceUtil
.
readBytes
(
"file/erweima.jpg"
);
String
fullPath
=
client
.
upload
(
content
,
path
);
String
fullPath
=
client
.
upload
(
content
,
path
,
"image/jpeg"
);
System
.
out
.
println
(
"访问地址:"
+
fullPath
);
if
(
false
)
{
byte
[]
bytes
=
client
.
getContent
(
path
);
...
...
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/local/LocalFileClientTest.java
浏览文件 @
5f8c569a
...
...
@@ -19,7 +19,7 @@ public class LocalFileClientTest {
// 上传文件
String
path
=
IdUtil
.
fastSimpleUUID
()
+
".jpg"
;
byte
[]
content
=
ResourceUtil
.
readBytes
(
"file/erweima.jpg"
);
String
fullPath
=
client
.
upload
(
content
,
path
);
String
fullPath
=
client
.
upload
(
content
,
path
,
"image/jpeg"
);
System
.
out
.
println
(
"访问地址:"
+
fullPath
);
client
.
delete
(
path
);
}
...
...
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java
浏览文件 @
5f8c569a
...
...
@@ -101,7 +101,7 @@ public class S3FileClientTest {
// 上传文件
String
path
=
IdUtil
.
fastSimpleUUID
()
+
".jpg"
;
byte
[]
content
=
ResourceUtil
.
readBytes
(
"file/erweima.jpg"
);
String
fullPath
=
client
.
upload
(
content
,
path
);
String
fullPath
=
client
.
upload
(
content
,
path
,
"image/jpeg"
);
System
.
out
.
println
(
"访问地址:"
+
fullPath
);
// 读取文件
if
(
true
)
{
...
...
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/sftp/SftpFileClientTest.java
浏览文件 @
5f8c569a
...
...
@@ -23,7 +23,7 @@ public class SftpFileClientTest {
// 上传文件
String
path
=
IdUtil
.
fastSimpleUUID
()
+
".jpg"
;
byte
[]
content
=
ResourceUtil
.
readBytes
(
"file/erweima.jpg"
);
String
fullPath
=
client
.
upload
(
content
,
path
);
String
fullPath
=
client
.
upload
(
content
,
path
,
"image/jpeg"
);
System
.
out
.
println
(
"访问地址:"
+
fullPath
);
if
(
false
)
{
byte
[]
bytes
=
client
.
getContent
(
path
);
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java
浏览文件 @
5f8c569a
...
...
@@ -31,8 +31,8 @@ import org.springframework.validation.annotation.Validated;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
javax.validation.Validator
;
import
java.util.Collection
;
import
java.time.LocalDateTime
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -193,7 +193,7 @@ public class FileConfigServiceImpl implements FileConfigService {
// 校验存在
FileConfigDO
config
=
this
.
validateFileConfigExists
(
id
);
if
(
Boolean
.
TRUE
.
equals
(
config
.
getMaster
()))
{
throw
exception
(
FILE_CONFIG_DELETE_FAIL_MASTER
);
throw
exception
(
FILE_CONFIG_DELETE_FAIL_MASTER
);
}
// 删除
fileConfigMapper
.
deleteById
(
id
);
...
...
@@ -230,7 +230,7 @@ public class FileConfigServiceImpl implements FileConfigService {
this
.
validateFileConfigExists
(
id
);
// 上传文件
byte
[]
content
=
ResourceUtil
.
readBytes
(
"file/erweima.jpg"
);
return
fileClientFactory
.
getFileClient
(
id
).
upload
(
content
,
IdUtil
.
fastSimpleUUID
()
+
".jpg"
);
return
fileClientFactory
.
getFileClient
(
id
).
upload
(
content
,
IdUtil
.
fastSimpleUUID
()
+
".jpg"
,
"image/jpeg"
);
}
@Override
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
浏览文件 @
5f8c569a
...
...
@@ -52,7 +52,7 @@ public class FileServiceImpl implements FileService {
// 上传到文件存储器
FileClient
client
=
fileConfigService
.
getMasterFileClient
();
Assert
.
notNull
(
client
,
"客户端(master) 不能为空"
);
String
url
=
client
.
upload
(
content
,
path
);
String
url
=
client
.
upload
(
content
,
path
,
type
);
// 保存到数据库
FileDO
file
=
new
FileDO
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论