mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-21 02:25:56 +08:00
Pre Merge pull request !489 from 丶Stone/dev
This commit is contained in:
commit
e6eb4ae0ed
@ -162,10 +162,11 @@ public class OssClient {
|
|||||||
* @param filePath 本地文件路径
|
* @param filePath 本地文件路径
|
||||||
* @param key 在 Amazon S3 中的对象键
|
* @param key 在 Amazon S3 中的对象键
|
||||||
* @param md5Digest 本地文件的 MD5 哈希值(可选)
|
* @param md5Digest 本地文件的 MD5 哈希值(可选)
|
||||||
|
* @param deleteAfterUpload 是否自动删除临时文件
|
||||||
* @return UploadResult 包含上传后的文件信息
|
* @return UploadResult 包含上传后的文件信息
|
||||||
* @throws OssException 如果上传失败,抛出自定义异常
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
*/
|
*/
|
||||||
public UploadResult upload(Path filePath, String key, String md5Digest) {
|
public UploadResult upload(Path filePath, String key, String md5Digest, Boolean deleteAfterUpload) {
|
||||||
try {
|
try {
|
||||||
// 构建上传请求对象
|
// 构建上传请求对象
|
||||||
FileUpload fileUpload = transferManager.uploadFile(
|
FileUpload fileUpload = transferManager.uploadFile(
|
||||||
@ -187,10 +188,11 @@ public class OssClient {
|
|||||||
// 捕获异常并抛出自定义异常
|
// 捕获异常并抛出自定义异常
|
||||||
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]");
|
||||||
} finally {
|
} finally {
|
||||||
// 无论上传是否成功,最终都会删除临时文件
|
if (deleteAfterUpload){
|
||||||
FileUtils.del(filePath);
|
FileUtils.del(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传 InputStream 到 Amazon S3
|
* 上传 InputStream 到 Amazon S3
|
||||||
@ -322,11 +324,12 @@ public class OssClient {
|
|||||||
*
|
*
|
||||||
* @param file 要上传的文件
|
* @param file 要上传的文件
|
||||||
* @param suffix 对象键的后缀
|
* @param suffix 对象键的后缀
|
||||||
|
* @param deleteAfterUpload 是否自动删除临时文件
|
||||||
* @return UploadResult 包含上传后的文件信息
|
* @return UploadResult 包含上传后的文件信息
|
||||||
* @throws OssException 如果上传失败,抛出自定义异常
|
* @throws OssException 如果上传失败,抛出自定义异常
|
||||||
*/
|
*/
|
||||||
public UploadResult uploadSuffix(File file, String suffix) {
|
public UploadResult uploadSuffix(File file, String suffix, Boolean deleteAfterUpload) {
|
||||||
return upload(file.toPath(), getPath(properties.getPrefix(), suffix), null);
|
return upload(file.toPath(), getPath(properties.getPrefix(), suffix), null, deleteAfterUpload);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -60,6 +60,15 @@ public interface ISysOssService {
|
|||||||
*/
|
*/
|
||||||
SysOssVo upload(File file);
|
SysOssVo upload(File file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件到对象存储服务,并保存文件信息到数据库
|
||||||
|
*
|
||||||
|
* @param file 要上传的文件对象
|
||||||
|
* @param deleteAfterUpload 是否自动删除临时文件
|
||||||
|
* @return 上传成功后的 SysOssVo 对象,包含文件信息
|
||||||
|
*/
|
||||||
|
SysOssVo upload(File file, Boolean deleteAfterUpload);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件下载方法,支持一次性下载完整文件
|
* 文件下载方法,支持一次性下载完整文件
|
||||||
*
|
*
|
||||||
|
|||||||
@ -196,10 +196,22 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SysOssVo upload(File file) {
|
public SysOssVo upload(File file) {
|
||||||
|
return this.upload(file, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件到对象存储服务,并保存文件信息到数据库
|
||||||
|
*
|
||||||
|
* @param file 要上传的文件对象
|
||||||
|
* @param deleteAfterUpload 是否自动删除临时文件
|
||||||
|
* @return 上传成功后的 SysOssVo 对象,包含文件信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SysOssVo upload(File file, Boolean deleteAfterUpload) {
|
||||||
String originalfileName = file.getName();
|
String originalfileName = file.getName();
|
||||||
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
||||||
OssClient storage = OssFactory.instance();
|
OssClient storage = OssFactory.instance();
|
||||||
UploadResult uploadResult = storage.uploadSuffix(file, suffix);
|
UploadResult uploadResult = storage.uploadSuffix(file, suffix, deleteAfterUpload);
|
||||||
// 保存文件信息
|
// 保存文件信息
|
||||||
return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult);
|
return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user