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