Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
6f3033b2
Commit
6f3033b2
authored
Aug 15, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
媒体工具类
parent
b27f5e7c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
ch-core/src/main/java/com/wwdz/ch/core/storage/QiniuStorage.java
.../src/main/java/com/wwdz/ch/core/storage/QiniuStorage.java
+25
-0
ch-core/src/main/java/com/wwdz/ch/core/util/MediaUtil.java
ch-core/src/main/java/com/wwdz/ch/core/util/MediaUtil.java
+1
-1
No files found.
ch-core/src/main/java/com/wwdz/ch/core/storage/QiniuStorage.java
View file @
6f3033b2
...
@@ -9,6 +9,10 @@ import java.nio.file.Path;
...
@@ -9,6 +9,10 @@ import java.nio.file.Path;
import
java.util.Base64
;
import
java.util.Base64
;
import
java.util.stream.Stream
;
import
java.util.stream.Stream
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.MediaTypeEnum
;
import
com.wwdz.ch.core.util.MediaUtil
;
import
com.xxdxxs.utils.CommonUtils
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils.JsonUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
...
@@ -196,4 +200,25 @@ public class QiniuStorage implements Storage {
...
@@ -196,4 +200,25 @@ public class QiniuStorage implements Storage {
public
String
generateUrl
(
String
keyName
)
{
public
String
generateUrl
(
String
keyName
)
{
return
endpoint
+
"/"
+
keyName
;
return
endpoint
+
"/"
+
keyName
;
}
}
/**
* 原图片地址没尺寸信息的加上尺寸信息重新上传
* @param imageUrl
* @return keyName
*/
public
String
reStore
(
String
imageUrl
)
{
try
{
URL
url
=
new
URL
(
imageUrl
);
InputStream
inputStream
=
url
.
openStream
();
BufferedImage
bufferedImage
=
ImageIO
.
read
(
inputStream
);
String
keyName
=
CommConsts
.
UPLOAD_PRE_DIRECTORY
+
CommonUtils
.
getUUID
()
+
"_"
+
bufferedImage
.
getWidth
()
+
"x"
+
bufferedImage
.
getHeight
()
+
"."
+
MediaTypeEnum
.
IMAGE_JPG
.
getExt
();
InputStream
imageStream
=
MediaUtil
.
bufferedImageToInputStream
(
bufferedImage
,
MediaTypeEnum
.
IMAGE_JPG
.
getExt
());
store
(
imageStream
,
1
,
MediaTypeEnum
.
IMAGE_JPG
.
getMime
(),
keyName
);
return
keyName
;
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取图片尺寸重新上传图片出错 : {}"
,
e
);
}
return
null
;
}
}
}
ch-core/src/main/java/com/wwdz/ch/core/util/MediaUtil.java
View file @
6f3033b2
...
@@ -77,7 +77,7 @@ public class MediaUtil {
...
@@ -77,7 +77,7 @@ public class MediaUtil {
* @param type 图片格式(eg:jpg、png)
* @param type 图片格式(eg:jpg、png)
* @return
* @return
*/
*/
p
rivate
static
InputStream
bufferedImageToInputStream
(
BufferedImage
image
,
String
type
)
{
p
ublic
static
InputStream
bufferedImageToInputStream
(
BufferedImage
image
,
String
type
)
{
try
(
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
())
{
try
(
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
())
{
ImageIO
.
write
(
image
,
type
,
os
);
ImageIO
.
write
(
image
,
type
,
os
);
return
new
ByteArrayInputStream
(
os
.
toByteArray
());
return
new
ByteArrayInputStream
(
os
.
toByteArray
());
...
...
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