forked from dyf/fys-Multi-tenant
WEB:导入设备数据
This commit is contained in:
@ -60,6 +60,9 @@ public interface ISysOssService {
|
||||
*/
|
||||
SysOssVo upload(File file);
|
||||
|
||||
|
||||
public SysOssVo upload(byte[] data, String fileName);
|
||||
|
||||
/**
|
||||
* 文件下载方法,支持一次性下载完整文件
|
||||
*
|
||||
|
@ -219,6 +219,36 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
||||
return buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 上传二进制数据到对象存储服务,并保存文件信息到数据库
|
||||
*
|
||||
* @param data 要上传的二进制数据
|
||||
* @param fileName 要上传的文件名(包括扩展名)
|
||||
* @return 上传成功后的 SysOssVo 对象,包含文件信息
|
||||
* @throws ServiceException 如果上传过程中发生异常,则抛出 ServiceException 异常
|
||||
*/
|
||||
@Override
|
||||
public SysOssVo upload(byte[] data, String fileName) {
|
||||
if (data == null || data.length == 0) {
|
||||
throw new ServiceException("上传的数据为空");
|
||||
}
|
||||
if (StringUtils.isBlank(fileName)) {
|
||||
throw new ServiceException("文件名不能为空");
|
||||
}
|
||||
|
||||
String suffix = StringUtils.substring(fileName, fileName.lastIndexOf("."), fileName.length());
|
||||
OssClient storage = OssFactory.instance();
|
||||
|
||||
UploadResult uploadResult;
|
||||
uploadResult = storage.uploadSuffix(data, suffix, "image/jpeg"); // 假设是图片类型,可以根据实际需要修改
|
||||
|
||||
// 保存文件信息
|
||||
return buildResultEntity(fileName, suffix, storage.getConfigKey(), uploadResult);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private SysOssVo buildResultEntity(String originalfileName, String suffix, String configKey, UploadResult uploadResult) {
|
||||
SysOss oss = new SysOss();
|
||||
|
Reference in New Issue
Block a user