Merge branch 'feature/file_preview' into 'master'
appCode:cms单独处理上传 See merge request infra/oss!64
This commit is contained in:
commit
1000f6dfa0
@ -21,7 +21,7 @@ public interface BaseS3Service {
|
|||||||
/**
|
/**
|
||||||
* upload file
|
* upload file
|
||||||
*/
|
*/
|
||||||
String uploadByStream(String bucketName, String tgtFileKey, String fileName, InputStream srcStream);
|
String uploadByStream(String bucketName, String tgtFileKey, String fileName, String appCode, InputStream srcStream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* upload multi file
|
* upload multi file
|
||||||
|
|||||||
@ -32,6 +32,8 @@ import static cn.axzo.oss.common.constans.CommonConstants.APP_PRO_BUCKET_NAME;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class AliOssServiceImpl implements AliOssService {
|
public class AliOssServiceImpl implements AliOssService {
|
||||||
|
|
||||||
|
private static final String APPCODE_CMS = "cms";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AliOssClient aliOssClient;
|
private AliOssClient aliOssClient;
|
||||||
|
|
||||||
@ -42,15 +44,19 @@ public class AliOssServiceImpl implements AliOssService {
|
|||||||
* upload file
|
* upload file
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String uploadByStream(String bucketName, String tgtFileKey, String fileName, InputStream srcStream) {
|
public String uploadByStream(String bucketName, String tgtFileKey, String fileName, String appCode, InputStream srcStream) {
|
||||||
OSS client = aliOssClient.getClient();
|
OSS client = aliOssClient.getClient();
|
||||||
try {
|
try {
|
||||||
|
if (APPCODE_CMS.equals(appCode)) {
|
||||||
|
client.putObject(bucketName, tgtFileKey, srcStream);
|
||||||
|
} else {
|
||||||
// 创建上传文件的元信息,通过文件云信息设置HTTP Header
|
// 创建上传文件的元信息,通过文件云信息设置HTTP Header
|
||||||
ObjectMetadata metadata = new ObjectMetadata();
|
ObjectMetadata metadata = new ObjectMetadata();
|
||||||
// 设置内容被下载时的名称
|
// 设置内容被下载时的名称
|
||||||
metadata.setContentDisposition("attachment;filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\"");
|
metadata.setContentDisposition("attachment;filename=\"" + URLEncoder.encode(fileName, "utf-8") + "\"");
|
||||||
metadata.setContentEncoding("utf-8");
|
metadata.setContentEncoding("utf-8");
|
||||||
client.putObject(bucketName, tgtFileKey, srcStream, metadata);
|
client.putObject(bucketName, tgtFileKey, srcStream, metadata);
|
||||||
|
}
|
||||||
} catch (OSSException e) {
|
} catch (OSSException e) {
|
||||||
LogUtil.error("uploadByStream OSSException", e);
|
LogUtil.error("uploadByStream OSSException", e);
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@ -27,7 +27,7 @@ public interface FileManager {
|
|||||||
* @param fileContent
|
* @param fileContent
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String uploadByStream(String bulkName, String keyPath, String fileName, byte[] fileContent);
|
String uploadByStream(String bulkName, String keyPath, String fileName, String appCode, byte[] fileContent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文件
|
* 下载文件
|
||||||
|
|||||||
@ -38,11 +38,11 @@ public class FileManagerImpl implements FileManager {
|
|||||||
* @param bulkName 默认的取值为
|
* @param bulkName 默认的取值为
|
||||||
* @param keyPath key的前置路径
|
* @param keyPath key的前置路径
|
||||||
*/
|
*/
|
||||||
public String uploadByStream(String bulkName, String keyPath, String fileName, byte[] fileContent) {
|
public String uploadByStream(String bulkName, String keyPath, String fileName, String appCode, byte[] fileContent) {
|
||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(fileContent);
|
InputStream inputStream = new ByteArrayInputStream(fileContent);
|
||||||
|
|
||||||
return aliOssService.uploadByStream(bulkName, keyPath, fileName, inputStream);
|
return aliOssService.uploadByStream(bulkName, keyPath, fileName, appCode, inputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -465,8 +465,8 @@ public class FileServiceImpl implements FileService {
|
|||||||
String tgtFileKey = Utility.generateFileKey(fileUploadConfig.getDirectory(), uuid, fileConform);
|
String tgtFileKey = Utility.generateFileKey(fileUploadConfig.getDirectory(), uuid, fileConform);
|
||||||
|
|
||||||
// 上传文件
|
// 上传文件
|
||||||
String fileUrl = fileManager.uploadByStream(
|
String fileUrl = fileManager.uploadByStream(fileUploadConfig.getBucketName(), tgtFileKey, dto.getFileName(),
|
||||||
fileUploadConfig.getBucketName(), tgtFileKey, dto.getFileName(), dto.getFileContent());
|
dto.getAppCode(), dto.getFileContent());
|
||||||
|
|
||||||
// 保存失败
|
// 保存失败
|
||||||
if (Utility.isBlank(fileUrl)) {
|
if (Utility.isBlank(fileUrl)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user