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
474f7328
Commit
474f7328
authored
Jan 15, 2019
by
songxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug 内部上传图片webp处理
parent
b711008d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
2 deletions
+56
-2
pom.xml
pcloud-common/pom.xml
+6
-0
ImageUtils.java
...mon/src/main/java/com/pcloud/common/utils/ImageUtils.java
+36
-0
OssUtils.java
...rc/main/java/com/pcloud/common/utils/aliyun/OssUtils.java
+14
-2
No files found.
pcloud-common/pom.xml
View file @
474f7328
...
...
@@ -384,6 +384,12 @@
<version>
2.0
</version>
</dependency>
<!-- util sdk -->
<dependency>
<groupId>
com.dcg.sdk
</groupId>
<artifactId>
util-sdk
</artifactId>
<version>
1.0.0
</version>
</dependency>
</dependencies>
</project>
pcloud-common/src/main/java/com/pcloud/common/utils/ImageUtils.java
View file @
474f7328
...
...
@@ -14,9 +14,12 @@ import javax.imageio.ImageIO;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.dcg.util.StringUtils
;
import
com.itextpdf.text.Image
;
import
com.pcloud.common.constant.AliyunConstant
;
import
com.pcloud.common.constant.FilePathConst
;
import
com.pcloud.common.constant.ImageConstant
;
import
com.pcloud.common.entity.UploadResultInfo
;
import
com.pcloud.common.enums.ImageEnum
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.FileException
;
...
...
@@ -688,4 +691,37 @@ public class ImageUtils {
return
size
;
}
/**
* 上传的图片转换成webpO
*
* @param localFilePath
* 源文件的本地路径
* @param httpUrl
* 源文件上传后的路径,主要用于子文件上传时对应http文件路径
*/
public
static
UploadResultInfo
toWebp
(
String
fileUrl
)
{
String
fileNameAll
=
FileUtils
.
getFileNameAll
(
fileUrl
);
String
localFilePath
=
FilePathConst
.
DOWNLOAD_PATH
+
fileNameAll
;
FileUtils
.
downloadFileFromUrl
(
fileUrl
,
localFilePath
);
String
tragetPath
=
null
;
try
{
tragetPath
=
com
.
dcg
.
util
.
ImageUtils
.
transcodeToWebp
(
localFilePath
,
80
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【IMAGE】图片转换成webp失败:"
+
e
.
getMessage
(),
e
);
return
null
;
}
if
(
StringUtils
.
isEmpty
(
tragetPath
))
{
return
null
;
}
try
{
return
OssUtils
.
uploadLocalFile4Child
(
tragetPath
,
fileUrl
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【IMAGE】图片转换成webp,上传失败:"
+
e
.
getMessage
(),
e
);
}
finally
{
FileUtils
.
deleteFile
(
localFilePath
);
FileUtils
.
deleteFile
(
tragetPath
);
}
return
null
;
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/aliyun/OssUtils.java
View file @
474f7328
...
...
@@ -35,6 +35,7 @@ import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobResponse.MediaInfoJob.
import
com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobRequest
;
import
com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobResponse.SnapshotJob
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.dcg.util.FileTypeUtils
;
import
com.pcloud.common.constant.AliyunConstant
;
import
com.pcloud.common.constant.FilePathConst
;
import
com.pcloud.common.constant.UrlConstant
;
...
...
@@ -147,7 +148,13 @@ public class OssUtils {
String
fileType
=
FileUtils
.
getFileType
(
filePath
);
String
outObjectKey
=
getOutObjectKey
(
AliyunEnum
.
UPLOAD
.
value
,
fileName
,
fileType
);
uploadPointFile2OSS
(
filePath
,
AliyunConstant
.
FILE_BUCKET
,
outObjectKey
);
return
getResultInfo
(
outObjectKey
,
new
File
(
filePath
).
length
(),
null
,
AliyunConstant
.
FILE_BUCKET
);
UploadResultInfo
uploadResultInfo
=
getResultInfo
(
outObjectKey
,
new
File
(
filePath
).
length
(),
null
,
AliyunConstant
.
FILE_BUCKET
);
// 如果上传的是图片转换成webp
if
(
uploadResultInfo
!=
null
&&
FileTypeUtils
.
equalsGatherName
(
fileType
,
FileTypeUtils
.
IMAGE
))
{
ImageUtils
.
toWebp
(
uploadResultInfo
.
getUrl
());
}
return
uploadResultInfo
;
}
/**
...
...
@@ -200,7 +207,12 @@ public class OssUtils {
throws
FileException
{
String
outObjectKey
=
getOutObjectKey
(
AliyunEnum
.
UPLOAD
.
value
,
null
,
fileType
);
uploadFileStream2OSS
(
is
,
AliyunConstant
.
FILE_BUCKET
,
outObjectKey
);
return
getResultInfo
(
outObjectKey
,
null
,
null
,
AliyunConstant
.
FILE_BUCKET
);
UploadResultInfo
uploadResultInfo
=
getResultInfo
(
outObjectKey
,
null
,
null
,
AliyunConstant
.
FILE_BUCKET
);
// 如果上传的是图片转换成webp
if
(
uploadResultInfo
!=
null
&&
FileTypeUtils
.
equalsGatherName
(
fileType
,
FileTypeUtils
.
IMAGE
))
{
ImageUtils
.
toWebp
(
uploadResultInfo
.
getUrl
());
}
return
uploadResultInfo
;
}
/**
...
...
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