Commit 6eb1b6a1 by 朱亚洁

fixbug:[none]语音转码

parent c668da83
......@@ -92,9 +92,6 @@ public class OssUtils {
/**
* 获取ACS客户端
*
* @param bucketName
* @return
*/
private static MpcClient initAcsClient(String bucketName) {
try {
......@@ -114,9 +111,6 @@ public class OssUtils {
/**
* 获取ACS客户端
*
* @param bucketName
* @return
*/
private static MpcClient getAcsClient(String bucketName) {
if (AliyunConstant.LIVE_BUCKET.equals(bucketName)) {
......@@ -137,8 +131,6 @@ public class OssUtils {
*
* @param filePath 源文件物理地址
* @param fileName 源文件名称,可为null
* @return
* @throws FileException
*/
public static UploadResultInfo uploadLocalFile(String filePath, String fileName) throws FileException {
return uploadLocalFile4CustomName(filePath, null);
......@@ -149,8 +141,6 @@ public class OssUtils {
*
* @param filePath 源文件物理地址
* @param fileName 源文件名称,可为null
* @return
* @throws FileException
*/
public static UploadResultInfo uploadLocalFile4CustomName(String filePath, String fileName) throws FileException {
String fileType = FileUtils.getFileType(filePath);
......@@ -170,8 +160,6 @@ public class OssUtils {
*
* @param filePath 子文件本地路径
* @param parentFileUrl 仅限OSS的全路径,其他本地文件路径均不支持
* @return
* @throws FileException
*/
public static UploadResultInfo uploadLocalFile4Child(String filePath, String parentFileUrl) throws FileException {
String fileType = FileUtils.getFileType(filePath);
......@@ -186,8 +174,6 @@ public class OssUtils {
* @param buff 源文件字节数组
* @param fileName 源文件名称不带后缀,可为null
* @param fileType 源文件后缀
* @return
* @throws FileException
*/
public static UploadResultInfo uploadFileByte(byte[] buff, String fileName, String fileType) throws FileException {
return uploadFileStream(new ByteArrayInputStream(buff), fileName, fileType);
......@@ -199,8 +185,6 @@ public class OssUtils {
* @param is 源文件流
* @param fileName 源文件名称不带后缀,可为null
* @param fileType 源文件后缀
* @return
* @throws FileException
*/
public static UploadResultInfo uploadFileStream(InputStream is, String fileName, String fileType)
throws FileException {
......@@ -216,12 +200,6 @@ public class OssUtils {
/**
* 文件流上传到aliOSS
*
* @param is
* @param bucketName
* @param objectKey
* @return
* @throws FileException
*/
@SneakyThrows
private static OSSFileDO uploadFileStream2OSS(InputStream is, String bucketName, String objectKey) {
......@@ -242,19 +220,14 @@ public class OssUtils {
client.close();
}
//oss%2Ftranscode%2Faudio%2Fmp3%2Ftest_20200529150529182.mp3
if (!StringUtil.isEmpty(ossFileDO.getObject()) && ossFileDO.getObject().contains("%2F")){
ossFileDO.setObject(ossFileDO.getObject().replace("%2F","/"));
if (!StringUtil.isEmpty(ossFileDO.getObject()) && ossFileDO.getObject().contains("%2F")) {
ossFileDO.setObject(ossFileDO.getObject().replace("%2F", "/"));
}
return ossFileDO;
}
/**
* 断点续传上传文件到aliOSS
*
* @param filePath
* @param bucketName
* @param objectKey
* @return
*/
@SneakyThrows
private static OSSFileDO uploadPointFile2OSS(String filePath, String bucketName, String objectKey)
......@@ -286,19 +259,14 @@ public class OssUtils {
ossClient.close();
}
//oss%2Ftranscode%2Faudio%2Fmp3%2Ftest_20200529150529182.mp3
if (!StringUtil.isEmpty(ossFileDO.getObject()) && ossFileDO.getObject().contains("%2F")){
ossFileDO.setObject(ossFileDO.getObject().replace("%2F","/"));
if (!StringUtil.isEmpty(ossFileDO.getObject()) && ossFileDO.getObject().contains("%2F")) {
ossFileDO.setObject(ossFileDO.getObject().replace("%2F", "/"));
}
return ossFileDO;
}
/**
* 断点续传上传文件到aliOSS
*
* @param filePath
* @param bucketName
* @param objectKey
* @return
*/
@SneakyThrows
private static DownloadFileResult downloadPointFile2OSS(String filePath, String outFilePath, String bucketName, String objectKey)
......@@ -330,13 +298,12 @@ public class OssUtils {
}
return result;
}
/**
* 提交MP4转码作业 new
*
* @param fileName 源文件的名称不带后缀,可为null
* @param filePath 源文件本地路径
* @return
* @throws FileException
*/
public static String submitTranscodeJobMp4(String fileName, String filePath) throws FileException {
String[] result = submitTranscodeJobMp4Ex(fileName, filePath);
......@@ -346,10 +313,7 @@ public class OssUtils {
/**
* 提交MP4转码作业 new
*
* @param fileName
* @param filePath
* @return [0]:jobId,转码作业ID;[1]:转码后的地址
* @throws FileException
*/
public static String[] submitTranscodeJobMp4Ex(String fileName, String filePath) throws FileException {
LOGGER.info("【aliOSS】提交MP4转码作业.[filePath]=" + filePath);
......@@ -367,7 +331,6 @@ public class OssUtils {
* @param buff 源文件流
* @param fileName 源文件的名称不带后缀,可为null
* @param fileType 源文件的后缀
* @return
*/
public static String submitTranscodeJobMp4(byte[] buff, String fileName, String fileType) throws FileException {
LOGGER.info("【aliOSS】提交MP4转码作业.");
......@@ -385,8 +348,6 @@ public class OssUtils {
*
* @param fileName 源文件的名称不带后缀,可为null
* @param filePath 源文件本地路径
* @return
* @throws FileException
*/
public static String submitTranscodeJobMp3(String fileName, String filePath) throws FileException {
String[] result = submitTranscodeJobMp3Ex(fileName, filePath);
......@@ -396,10 +357,7 @@ public class OssUtils {
/**
* 提交MP3转码作业 new
*
* @param fileName
* @param filePath
* @return [0]:jobId,转码作业ID;[1]:转码后的地址
* @throws FileException
*/
public static String[] submitTranscodeJobMp3Ex(String fileName, String filePath) throws FileException {
LOGGER.info("【aliOSS】提交MP3转码作业.[filePath]=" + filePath);
......@@ -417,7 +375,6 @@ public class OssUtils {
* @param is 源文件流
* @param fileName 源文件的名称不带后缀,可为null
* @param fileType 源文件的后缀
* @return
*/
@Deprecated
public static String submitTranscodeJobMp3(InputStream is, String fileName, String fileType) throws FileException {
......@@ -436,8 +393,6 @@ public class OssUtils {
* @param buff 文件
* @param fileName 源文件的名称不带后缀,可为null
* @param fileType 上传的文件后缀
* @return
* @throws FileException
*/
public static String submitTranscodeJobMp3(byte[] buff, String fileName, String fileType) throws FileException {
LOGGER.info("【aliOSS】提交MP3转码作业.");
......@@ -452,10 +407,6 @@ public class OssUtils {
/**
* 转码作业,同步的方式 new
*
* @param fileUrl
* @return
* @throws FileException
*/
public static UploadResultInfo submitTranscodeJobSync(String fileUrl) throws FileException {
String bucketName = AliyunConstant.getBucketName(fileUrl);
......@@ -468,8 +419,6 @@ public class OssUtils {
*
* @param fileName 文件名称
* @param filePath 文件地址
* @return
* @throws FileException
*/
public static String transcodeJob(String fileName, String filePath) throws FileException {
String[] result = transcodeJobEx(fileName, filePath, null, null);
......@@ -479,7 +428,6 @@ public class OssUtils {
/**
* 转码作业 new
*
* @param fileName
* @param fileUrl 文件地址
* @param outFileType 输出文件类型
* @param waterMarkContent 视频水印文本,如果不需要水印传null
......@@ -497,13 +445,6 @@ public class OssUtils {
/**
* 已经存在于OSS中的文件转码 new
*
* @param fileUrl
* @param fileName
* @param fileType
* @param outFileType
* @param waterMarkContent
* @return
*/
private static String[] transcodeJobExistOSS(String fileUrl, String fileName, String fileType, String outFileType,
String waterMarkContent) {
......@@ -529,11 +470,6 @@ public class OssUtils {
/**
* 不存在于OSS中的文件转码,要先上传 new
*
* @param fileUrl
* @param fileName
* @param fileType
* @return
*/
private static String[] transcodeJobNotExistOSS(String fileUrl, String fileName, String fileType) {
LOGGER.info("【aliOSS】不存在于OSS中的文件转码.<START>.[fileUrl]=" + fileUrl);
......@@ -547,9 +483,6 @@ public class OssUtils {
/**
* 获取文件所在的BUCKET名称
*
* @param fileUrl
* @return
*/
private static String getInputBucketName(String fileUrl) {
String inputBucketName = AliyunConstant.getBucketName(fileUrl);
......@@ -622,10 +555,6 @@ public class OssUtils {
/**
* 同步的方式获取转码后的结果 new
*
* @param jobId
* @return
* @throws FileException
*/
private static UploadResultInfo transcodeJobResultSync(String jobId, String bucketName) throws FileException {
LOGGER.info("【aliOSS】同步获取转码后的结果.<START>.[jobId]=" + jobId + ",[bucketName]=" + bucketName);
......@@ -650,10 +579,9 @@ public class OssUtils {
}
/**
* 转码作业
* * @param null
* 转码作业 * @param null
*/
private static String[] transcodeJob(OSSFileDO inputFile,String templateId,String outObjectKey, CreateTranscodingRequest.Watermark[] watermarkArray, List<String> mergeUrls){
private static String[] transcodeJob(OSSFileDO inputFile, String templateId, String outObjectKey, CreateTranscodingRequest.Watermark[] watermarkArray, List<String> mergeUrls) {
// 媒体处理服务构造方法
MpcClient mpcClient = getAcsClient(inputFile.getBucket());
......@@ -796,11 +724,9 @@ public class OssUtils {
return mergeJsons;
}
*/
/**
* 组装视频水印参数
*
* @param content
* @return
*/
/* private static JSONArray getWaterMarkConfig(String content) {
if (StringUtil.isEmpty(content)) {
......@@ -819,8 +745,7 @@ public class OssUtils {
waterMarkConfigArray.add(waterMarkConfig);
return waterMarkConfigArray;
}*/
private static CreateTranscodingRequest.Watermark[] getWaterMarkConfig(String content){
private static CreateTranscodingRequest.Watermark[] getWaterMarkConfig(String content) {
if (StringUtil.isEmpty(content)) {
return null;
}
......@@ -1018,11 +943,11 @@ public class OssUtils {
/**
* 提交视频截图任务,成功返回图片地址
*
* @author:zhuyajie
* @date:2020/6/1 20:08
* * @param null
* @date:2020/6/1 20:08 * @param null
*/
public static String submitSnapshotJob(String fileUrl, int time){
public static String submitSnapshotJob(String fileUrl, int time) {
LOGGER.info("【aliOSS】提交MP4截图作业,<START>.[fileUrl]=" + fileUrl);
String fileType = FileUtils.getFileType(fileUrl);
if (!FileUtils.VIDEO.equals(FileUtils.getGatherName(fileType))) {
......@@ -1092,7 +1017,7 @@ public class OssUtils {
}
}
public static String getThumnailObject(String bucketName, String taskId){
public static String getThumnailObject(String bucketName, String taskId) {
int total = 0;
while (true) {
// 如果超过1小时,认定转换失败
......@@ -1128,15 +1053,15 @@ public class OssUtils {
QueryThumbTaskResponse queryThumbTaskResponse = mpcClient.queryThumbnailsTask(queryThumbTaskRequest);
// 返回消息
System.out.println(new Gson().toJson(queryThumbTaskResponse));
if (ListUtils.isEmpty(queryThumbTaskResponse.getTaskArray())){
if (ListUtils.isEmpty(queryThumbTaskResponse.getTaskArray())) {
return outObject;
}
if (QueryThumbTaskResponse.ThumbTask.StatusEnum.SUCCEEDED.equals(queryThumbTaskResponse.getTaskArray().get(0).getStatus())) {
QueryThumbTaskResponse.ThumbTask thumbTask = queryThumbTaskResponse.getTaskArray().get(0);
if (!ListUtils.isEmpty(thumbTask.getThumbnailInfo())){
if (!ListUtils.isEmpty(thumbTask.getThumbnailInfo())) {
String picName = thumbTask.getThumbnailInfo().get(0).getPicName();
outObject = URLDecoder.decode(thumbTask.getOutput().getObject()+"/"+picName, "UTF-8");
}else {
outObject = URLDecoder.decode(thumbTask.getOutput().getObject() + "/" + picName, "UTF-8");
} else {
outObject = "https://oss.5rs.me/oss/uploadfe/jpg/d026cd83cf2ff55e3f4b4493a6919712.jpg";//默认图
}
}
......@@ -1183,9 +1108,6 @@ public class OssUtils {
/**
* 组装转换后的地址(华东地区) new
*
* @param transcodeJobId
* @return
*/
public static UploadResultInfo getOSSResult(String transcodeJobId) throws FileException {
LOGGER.info("【aliOSS】组装转换后的地址(华东地区),<START>.[transcodeJobId]=" + transcodeJobId);
......@@ -1194,10 +1116,6 @@ public class OssUtils {
/**
* 组装转换后的地址,根据BUCKETNAME new
*
* @param transcodeJobId
* @return
* @throws FileException
*/
public static UploadResultInfo getOSSResultByRegion(String transcodeJobId, String buckectName)
throws FileException {
......@@ -1210,25 +1128,18 @@ public class OssUtils {
/**
* 组装转换后的地址
*
* @param transcodeJobId
* @return
* @throws FileException
*/
private static UploadResultInfo getOSSResult(String transcodeJobId, String outputBucketName) throws FileException {
if (StringUtil.isEmpty(transcodeJobId)) {
return new UploadResultInfo("ali", "ali转码作业失败[transcodeJobId=null]", false);
}
// Job transcodeJob = getTranscodeJob(transcodeJobId, outputBucketName);
QueryTranscodingResponse.QueryTranscodingInfo transcodeJob = getTranscodeJob(transcodeJobId,outputBucketName);
QueryTranscodingResponse.QueryTranscodingInfo transcodeJob = getTranscodeJob(transcodeJobId, outputBucketName);
return explainTranscodeResult(transcodeJob);
}
/**
* 获取转换作业情况
*
* @param transcodeJobId
* @return
*/
/*private static Job getTranscodeJob(String transcodeJobId, String bucketName) throws FileException {
QueryJobListRequest request = new QueryJobListRequest();
......@@ -1242,16 +1153,18 @@ public class OssUtils {
throw new FileException(FileException.FILE_CONVERT_FAIL, "获取转换作业情况失败");
}
}*/
private static QueryTranscodingResponse.QueryTranscodingInfo getTranscodeJob(String transcodeJobId, String bucketName){
private static QueryTranscodingResponse.QueryTranscodingInfo getTranscodeJob(String transcodeJobId, String bucketName) {
MpcClient mpcClient = OssUtils.initAcsClient(bucketName);
//设置查询转码任务ID
QueryTranscodingRequest queryTranscodingRequest=new QueryTranscodingRequest();
QueryTranscodingRequest queryTranscodingRequest = new QueryTranscodingRequest();
queryTranscodingRequest.setTaskId(transcodeJobId);
try {
//发送查询转码任务请求
QueryTranscodingResponse queryTranscodingResponse=mpcClient.queryTranscodingTask(queryTranscodingRequest);
QueryTranscodingResponse queryTranscodingResponse = mpcClient.queryTranscodingTask(queryTranscodingRequest);
System.out.println(new Gson().toJson(queryTranscodingResponse));
if (null == queryTranscodingResponse || ListUtils.isEmpty(queryTranscodingResponse.getTranscodingArray())) {
return null;
}
return queryTranscodingResponse.getTranscodingArray().get(0);
} catch (Exception e) {
LOGGER.error("【aliOSS】获取转换作业情况失败:" + e.getMessage(), e);
......@@ -1260,7 +1173,10 @@ public class OssUtils {
}
private static UploadResultInfo explainTranscodeResult(QueryTranscodingResponse.QueryTranscodingInfo transcodingInfo){
private static UploadResultInfo explainTranscodeResult(QueryTranscodingResponse.QueryTranscodingInfo transcodingInfo) {
if (null == transcodingInfo) {
return null;
}
String status = transcodingInfo.getStatus();
if ("FAILED".equals(status)) {
LOGGER.warn("【huawei】转换作业失败:[jobId]" + transcodingInfo.getTaskId() + ",[status]=" + status);
......@@ -1272,13 +1188,13 @@ public class OssUtils {
String objectKey = null;
String outputFileName = transcodingInfo.getOutputFileNames().get(0);
try {
objectKey = URLDecoder.decode(output.getObject()+"/"+outputFileName, "UTF-8");
objectKey = URLDecoder.decode(output.getObject() + "/" + outputFileName, "UTF-8");
} catch (Exception e) {
LOGGER.error("【aliOSS】组装转换后的地址失败:" + e.getMessage(), e);
return new UploadResultInfo("ali", "huawei转码作业失败", false);
}
// 文件大小
Long fileSize =transcodingInfo.getTranscodeDetail().getMultitaskInfo().get(0).getOutputFile().getSize();
Long fileSize = transcodingInfo.getTranscodeDetail().getMultitaskInfo().get(0).getOutputFile().getSize();
// 视频时长 音频时长
Integer duration = transcodingInfo.getTranscodeDetail().getMultitaskInfo().get(0).getOutputFile().getDuration();
return getResultInfo(objectKey, fileSize, duration.toString(), bucketName);
......@@ -1329,10 +1245,6 @@ public class OssUtils {
/**
* 获取媒体信息,仅限经过转码的音视频文件
*
* @param fileUrl
* @return
* @throws FileException
*/
public static OssMediaInfoDTO getMediaInfo(String fileUrl) throws FileException {
LOGGER.info("【aliOSS】获取媒体信息,仅限经过转码的音视频文件,<START>.[fileUrl]=" + fileUrl);
......@@ -1343,7 +1255,7 @@ public class OssUtils {
String bucketName = AliyunConstant.getBucketName(fileUrl);
ObjectMetadata objectMetadata = null;
try {
objectMetadata = getObjectMetadata(objectKey,bucketName);
objectMetadata = getObjectMetadata(objectKey, bucketName);
} catch (Exception e) {
LOGGER.error("【aliOSS】获取媒体信息失败:" + e.getMessage(), e);
}
......@@ -1363,9 +1275,6 @@ public class OssUtils {
/**
* 获取文件的元信息
*
* @param objectKey
* @return
*/
@SneakyThrows
public static ObjectMetadata getObjectMetadata(String objectKey, String bucketName) throws FileException {
......@@ -1379,10 +1288,6 @@ public class OssUtils {
/**
* 下载文件成byte[]
*
* @param fileUrl
* @return
* @throws FileException
*/
public static byte[] downloadFile2Byte(String fileUrl) throws FileException {
String objectKey = splitObjectKey(fileUrl);
......@@ -1427,31 +1332,22 @@ public class OssUtils {
/**
* 下载文件到本地()
*
* @param fileUrl
* @param outFilePath
*/
@SneakyThrows
public static void downloadFile(String fileUrl, String outFilePath) throws FileException {
String objectKey = splitObjectKey(fileUrl);
String bucketName = AliyunConstant.getBucketName(fileUrl);
try {
downloadPointFile2OSS(fileUrl,outFilePath,bucketName,objectKey);
downloadPointFile2OSS(fileUrl, outFilePath, bucketName, objectKey);
} catch (Exception e) {
LOGGER.error("【aliOSS】下载文件失败:" + e.getMessage(), e);
//下载失败再次尝试断点下载
downloadPointFile2OSS(fileUrl,outFilePath,bucketName,objectKey);
downloadPointFile2OSS(fileUrl, outFilePath, bucketName, objectKey);
}
}
/**
* 组装返回的文件信息 <br> isPrivateKey=true,表示地址可下载,但需要加上密钥,密钥生产使用方法getHashValue或者addUrlKey <br>
*
* @param objectKey
* @param size
* @param duration
* @param outputBucketName
* @return
*/
private static UploadResultInfo getResultInfo(String objectKey, Long size, String duration,
String outputBucketName) {
......@@ -1476,10 +1372,6 @@ public class OssUtils {
/**
* 组装转换后的地址
*
* @param objectKey
* @param outputBucketName
* @return
*/
private static String getOSSUrl(String objectKey, String outputBucketName) {
if (StringUtil.isEmpty(objectKey)) {
......@@ -1490,9 +1382,6 @@ public class OssUtils {
/**
* 从完整的HTTP路径中截取objectName
*
* @param fileUrl
* @return
*/
public static String splitObjectKey(String fileUrl) {
LOGGER.info("【aliOSS】从完整的HTTP路径中截取objectKey,<START>.[fileUrl]=" + fileUrl);
......@@ -1523,11 +1412,6 @@ public class OssUtils {
/**
* 组装输入文件Object路径
*
* @param aliyunEnum
* @param fileName
* @param fileType
* @return
*/
private static String getInObjectKey(AliyunEnum aliyunEnum, String fileName, String fileType) {
return getObjectKey(aliyunEnum, fileName, fileType);
......@@ -1535,11 +1419,6 @@ public class OssUtils {
/**
* 组装输出文件Object路径
*
* @param aliyunEnum
* @param fileName
* @param fileType
* @return
*/
private static String getOutObjectKey(AliyunEnum aliyunEnum, String fileName, String fileType) {
return getObjectKey(aliyunEnum, fileName, fileType);
......@@ -1548,10 +1427,6 @@ public class OssUtils {
/**
* 组装输出文件Object路径-转码
*
* @param aliyunEnum
* @param fileType
* @return
*/
private static String getTranscodeOutObjectKey(AliyunEnum aliyunEnum, String fileType) {
//用于“output”时,只需指定到转码结果期望存放的路径。
......@@ -1560,13 +1435,9 @@ public class OssUtils {
return new StringBuilder("oss/").append(aliyunEnum.value).append("/").append(gatherName).append("/")
.append(fileType).append("/").toString();
}
/**
* 组装ObjectKey
*
* @param aliyunEnum
* @param fileName
* @param fileType
* @return
*/
private static String getObjectKey(AliyunEnum aliyunEnum, String fileName, String fileType) {
fileName = StringUtil.isEmpty(fileName) ? UUIDUitl.taskName()
......@@ -1579,9 +1450,6 @@ public class OssUtils {
/**
* 获取文件下载加密密钥,默认有效期48小时 <br> 密钥需要结合域名https://download.5rs.me使用,可以在浏览器直接下载 <br>
*
* @param fileUrl
* @return
*/
public static String getHashValue(String fileUrl) {
return getHashValue(fileUrl, AliyunConstant.OSS_DEFAULT_TIME);
......@@ -1589,9 +1457,6 @@ public class OssUtils {
/**
* 获取文件下载加密密钥,长期有效 <br> 密钥需要结合域名https://download.5rs.me使用,可以在浏览器直接下载 <br>
*
* @param fileUrl
* @return
*/
public static String getHashValueLong(String fileUrl) {
return getHashValue(fileUrl, AliyunConstant.OSS_LONG_TIME);
......@@ -1600,9 +1465,7 @@ public class OssUtils {
/**
* 获取文件下载加密密钥 <br> 密钥需要结合域名https://download.5rs.me使用,可以在浏览器直接下载 <br>
*
* @param fileUrl
* @param second 秒,地址有效期
* @return
*/
public static String getHashValue(String fileUrl, long second) {
String objectKey = splitObjectKey(fileUrl);
......@@ -1621,7 +1484,6 @@ public class OssUtils {
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 <br> 默认有效期48小时
*
* @param fileUrl 文件URL全路径地址
* @return
*/
public static String urlAddKey(String fileUrl) {
return urlAddKey(fileUrl, AliyunConstant.OSS_DEFAULT_TIME);
......@@ -1631,7 +1493,6 @@ public class OssUtils {
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 <br> 长期有效
*
* @param fileUrl 文件URL全路径地址
* @return
*/
public static String urlAddKeyLong(String fileUrl) {
return urlAddKey(fileUrl, AliyunConstant.OSS_LONG_TIME);
......@@ -1642,7 +1503,6 @@ public class OssUtils {
*
* @param fileUrl 文件URL全路径地址
* @param second 秒,地址有效期
* @return
*/
public static String urlAddKey(String fileUrl, long second) {
String result = keyCheckFile(fileUrl);
......@@ -1654,7 +1514,6 @@ public class OssUtils {
*
* @param fileUrl 文件URL全路径地址
* @param second 秒,地址有效期
* @return
*/
public static String urlAddKeyChina(String fileUrl, long second) {
String result = keyCheckFile(fileUrl);
......@@ -1680,7 +1539,6 @@ public class OssUtils {
* 将文件URL生成带密钥的下载地址,返回的地址不带域名 <br> 默认有效期48小时
*
* @param fileUrl 文件URL全路径地址
* @return
*/
public static String urlAddKey2Sms(String fileUrl) {
return urlAddKey2Sms(fileUrl, AliyunConstant.OSS_DEFAULT_TIME);
......@@ -1690,7 +1548,6 @@ public class OssUtils {
* 将文件URL生成带密钥的下载地址,返回的地址不带域名 <br> 长期有效
*
* @param fileUrl 文件URL全路径地址
* @return
*/
public static String urlAddKeyLong2Sms(String fileUrl) {
return urlAddKey2Sms(fileUrl, AliyunConstant.OSS_LONG_TIME);
......@@ -1701,7 +1558,6 @@ public class OssUtils {
*
* @param fileUrl 文件URL全路径地址
* @param second 秒,地址有效期
* @return
*/
public static String urlAddKey2Sms(String fileUrl, long second) {
String keyUrl = urlAddKey(fileUrl, second);
......@@ -1711,9 +1567,6 @@ public class OssUtils {
/**
* 将文件URL生成带密钥的下载地址,返回的地址不带域名 <br>
*
* @param fileUrl
* @return
*/
public static String urlAddKeyLong2SmsOwn(String fileUrl) {
String keyUrl = urlAddKeyChina(fileUrl, AliyunConstant.OSS_LONG_TIME);
......@@ -1725,7 +1578,6 @@ public class OssUtils {
* 将文件URL生成带密钥的地址,可以在浏览器直接访问,并转换为短链接<br>
*
* @param fileUrl 文件URL全路径地址
* @return
*/
public static String urlAddKey2Short(String fileUrl) {
return urlAddKey2Short(fileUrl, AliyunConstant.OSS_DEFAULT_TIME);
......@@ -1735,7 +1587,6 @@ public class OssUtils {
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 ,并转换为短链接<br> 长期有效
*
* @param fileUrl 文件URL全路径地址
* @return
*/
public static String urlAddKeyLong2Short(String fileUrl) {
return urlAddKey2Short(fileUrl, AliyunConstant.OSS_LONG_TIME);
......@@ -1746,7 +1597,6 @@ public class OssUtils {
*
* @param fileUrl 文件URL全路径地址
* @param second 秒,地址有效期
* @return
*/
public static String urlAddKey2Short(String fileUrl, long second) {
String keyUrl = urlAddKeyChina(fileUrl, second);
......@@ -1757,10 +1607,8 @@ public class OssUtils {
/**
* 图片缩放,按宽度等比例缩放
*
* @param fileUrl
* @param width 目前最大支持1024,超过1024或者小于0都按1024计算
* @return 返回处理后的图片本地地址
* @throws FileException
*/
public static String imageWidthResize(String fileUrl, int width) throws FileException {
LOGGER.info("【aliOSS】图片缩放,<START>.[fileUrl]=" + fileUrl + ",[width]=" + width);
......@@ -1780,10 +1628,8 @@ public class OssUtils {
/**
* 图片缩放,按倍数百分比缩放
*
* @param fileUrl
* @param p 1-1000,倍数百分比。 小于100,即是缩小,大于100即是放大。
* @return 返回处理后的图片本地地址
* @throws FileException
*/
public static String imageResize(String fileUrl, int p) throws FileException {
LOGGER.info("【aliOSS】图片缩放,<START>.[fileUrl]=" + fileUrl + ",[p]=" + p);
......@@ -1803,10 +1649,8 @@ public class OssUtils {
/**
* 图片自动旋转
*
* @param fileUrl
* @param width 图片旋转以后的宽度,最大不能超过4096,传0则按原始宽度旋转
* @return 返回处理后的图片本地地址
* @throws FileException
*/
public static String imageAutoOrient(String fileUrl, int width) throws FileException {
LOGGER.info("【aliOSS】图片自动旋转,<START>.[fileUrl]=" + fileUrl);
......@@ -1829,13 +1673,11 @@ public class OssUtils {
/**
* 图片裁剪,如果图片带有旋转属性,会自动旋转纠正角度后在进行裁剪。
*
* @param fileUrl
* @param width 裁剪的宽度
* @param height 裁剪的高度
* @param x 左上角开始, 裁剪的X轴坐标
* @param y 左上角开始, 裁剪的Y轴坐标
* @return 返回处理后的图片本地地址
* @throws FileException
*/
public static String imageCrop(String fileUrl, int width, int height, int x, int y) throws FileException {
LOGGER.info("【aliOSS】图片裁剪,<START>.[fileUrl]=" + fileUrl);
......@@ -1856,14 +1698,6 @@ public class OssUtils {
/**
* <持久化>图片裁剪,如果图片带有旋转属性,会自动旋转纠正角度后在进行裁剪。
*
* @param fileUrl
* @param width
* @param height
* @param x
* @param y
* @return
* @throws FileException
*/
@SneakyThrows
public static OssImageCropDTO imageCropSaveas(String fileUrl, int width, int height, int x, int y)
......@@ -1885,10 +1719,10 @@ public class OssUtils {
ObsClient ossClient = getOSSClient(bucketName);
TemporarySignatureRequest temporarySignatureRequest = new TemporarySignatureRequest();
temporarySignatureRequest.setObjectKey(sourceKey);
Map<String, Object> queryParams =new HashMap<>();
queryParams.put("x-image-process",style.toString());
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("x-image-process", style.toString());
queryParams.put("x-image-save-object", ServiceUtils.toBase64(sourceKey.getBytes("UTF-8")));
queryParams.put("x-image-save-bucket",ServiceUtils.toBase64(bucketName.getBytes("UTF-8")));
queryParams.put("x-image-save-bucket", ServiceUtils.toBase64(bucketName.getBytes("UTF-8")));
temporarySignatureRequest.setQueryParams(queryParams);
temporarySignatureRequest.setBucketName(bucketName);
TemporarySignatureResponse response = ossClient.createTemporarySignature(temporarySignatureRequest);
......@@ -1908,9 +1742,6 @@ public class OssUtils {
/**
* 图片处理
*
* @param fileUrl
* @param style
*/
@SneakyThrows
private static String imageHandle(String fileUrl, String style) {
......@@ -1959,7 +1790,6 @@ public class OssUtils {
/**
* 图片增加水印
*
* @param fileUrl
* @return 返回处理后的图片网络地址
*/
public static String imageWatermark(String fileUrl, String watermarkContent) throws FileException {
......@@ -1985,8 +1815,6 @@ public class OssUtils {
* 图片增加水印(文本)
*
* @param ossImageDTO 原图地址
* @return
* @throws FileException
*/
public static String imageWatermark4Text(OssImageDTO ossImageDTO) {
LOGGER.info("【aliOSS】图片增加水印(文本),<START>.[ossImageDTO]=" + ossImageDTO);
......@@ -2028,8 +1856,6 @@ public class OssUtils {
*
* @param fileUrl 原图地址
* @param watermarkImageUrl 水印图片地址
* @return
* @throws FileException
*/
public static String imageWatermark4Image(String fileUrl, String watermarkImageUrl) throws FileException {
LOGGER.info("【aliOSS】图片增加水印(图片),<START>.[fileUrl]=" + fileUrl + ",[watermarkImageUrl]=" + watermarkImageUrl);
......@@ -2038,7 +1864,7 @@ public class OssUtils {
}
StringBuilder style = new StringBuilder("image/watermark");
// 水印图片地址,按主图大小的10%缩放
watermarkImageUrl = AliyunConstant.getBucketName(watermarkImageUrl)+"/" + splitObjectKey(watermarkImageUrl);
watermarkImageUrl = AliyunConstant.getBucketName(watermarkImageUrl) + "/" + splitObjectKey(watermarkImageUrl);
style.append(",image_" + new String(Base64.encode(watermarkImageUrl.getBytes())));
// 水印颜色,位置,偏移量
style.append(",g_br,t_90,x_10,y_10");
......@@ -2049,9 +1875,6 @@ public class OssUtils {
/**
* 图片水印处理
*
* @param fileUrl
* @param style
*/
@SneakyThrows
private static String imageWatermarkHandle(String fileUrl, String style) {
......@@ -2068,7 +1891,7 @@ public class OssUtils {
+ fileType;
FileUtils.creatFiles(localPath);
ObsObject obsObject = ossClient.getObject(request);
obsObjectToLocalFile(localPath,obsObject);
obsObjectToLocalFile(localPath, obsObject);
ossClient.close();
// 上传处理后的图片,并删除本地文件
UploadResultInfo uploadResultInfo = uploadLocalFile4CustomName(localPath, fileName);
......@@ -2078,9 +1901,6 @@ public class OssUtils {
/**
* 检查图片文件合法性,如果是本地文件先上传
*
* @param fileUrl
* @return
*/
private static String checkImageFileUrl(String fileUrl) throws BizException {
LOGGER.info("【aliOSS】检查文件合法性,<START>.[fileUrl]=" + fileUrl);
......@@ -2103,9 +1923,6 @@ public class OssUtils {
/**
* 计算图片水印文字大小
*
* @param fileUrl
* @return
*/
private static Integer caleImageFontSize(String fileUrl) {
LOGGER.info("【aliOSS】计算图片水印文字大小,<START>.[fileUrl]=" + fileUrl);
......@@ -2117,20 +1934,14 @@ public class OssUtils {
/**
* 获取OSS客户端
*
* @return
*/
private static ObsClient getOSSClient(String bucketName) {
return new ObsClient(AliyunConstant.MAIN_ACCESS_KEY_ID,
AliyunConstant.MAIN_ACCESS_KEY_SECRET,AliyunConstant.getOSSEndPoint(bucketName));
AliyunConstant.MAIN_ACCESS_KEY_SECRET, AliyunConstant.getOSSEndPoint(bucketName));
}
/**
* 判断object是否存在
*
* @param bucketName
* @param objectKey
* @return
*/
@SneakyThrows
private static boolean objectExist(String bucketName, String objectKey) {
......@@ -2144,7 +1955,6 @@ public class OssUtils {
/**
* 判断文件是存在001中
*
* @param fileUrl
* @return true:001,false:002
*/
public static boolean fileUrlExist001(String fileUrl) {
......@@ -2155,7 +1965,6 @@ public class OssUtils {
/**
* 判断文件是存在002中
*
* @param fileUrl
* @return true:001,false:002
*/
public static boolean fileUrlExist002(String fileUrl) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment