Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
4a84cf03
Commit
4a84cf03
authored
Aug 19, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片格式支持webp
parent
3bbbcdb0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
+21
-8
OSSFileService.java
...main/java/com/tanpu/community/service/OSSFileService.java
+21
-8
No files found.
community-service/src/main/java/com/tanpu/community/service/OSSFileService.java
View file @
4a84cf03
...
...
@@ -21,6 +21,7 @@ import javax.annotation.Resource;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -79,7 +80,8 @@ public class OSSFileService {
record
.
setFileId
(
id
);
record
.
setPreviewUrl
(
ossHelper
.
getPreSignedUrl
(
bucketName
,
key
));
record
.
setFileType
(
FileTypeEnum
.
IMAGE
.
getCode
());
HashMap
<
String
,
Integer
>
attr
=
getStringIntegerHashMap
(
data
);
// todo 上传非文件类型
HashMap
<
String
,
Integer
>
attr
=
getStringIntegerHashMap
(
data
,
"webp"
.
equals
(
suffix
));
record
.
setExtInfo
(
JsonUtil
.
toJson
(
attr
));
fileRecordMapper
.
insert
(
record
);
...
...
@@ -95,7 +97,9 @@ public class OSSFileService {
ossHelper
.
writeFile
(
bucketName
,
key
,
data
,
fileSuffix
);
}
private
HashMap
<
String
,
Integer
>
getStringIntegerHashMap
(
byte
[]
data
)
{
private
HashMap
<
String
,
Integer
>
getStringIntegerHashMap
(
byte
[]
data
,
boolean
isWebp
)
{
ByteArrayInputStream
bins
=
new
ByteArrayInputStream
(
data
);
BufferedImage
bi
=
null
;
try
{
...
...
@@ -104,26 +108,35 @@ public class OSSFileService {
e
.
printStackTrace
();
}
HashMap
<
String
,
Integer
>
attr
=
new
HashMap
<>();
attr
.
put
(
"width"
,
bi
.
getWidth
());
attr
.
put
(
"height"
,
bi
.
getHeight
());
if
(
bi
!=
null
)
{
attr
.
put
(
"width"
,
bi
.
getWidth
());
attr
.
put
(
"height"
,
bi
.
getHeight
());
}
if
(
isWebp
)
{
// webp格式图片读取宽高
byte
[]
bytes
=
Arrays
.
copyOf
(
data
,
30
);
int
width
=
((
int
)
bytes
[
27
]
&
0xff
)
<<
8
|
((
int
)
bytes
[
26
]
&
0xff
);
int
height
=
((
int
)
bytes
[
29
]
&
0xff
)
<<
8
|
((
int
)
bytes
[
28
]
&
0xff
);
attr
.
put
(
"width"
,
width
);
attr
.
put
(
"height"
,
height
);
}
return
attr
;
}
public
FileRecordEntity
queryById
(
String
fileId
)
{
return
fileRecordMapper
.
selectOne
(
new
LambdaQueryWrapper
<
FileRecordEntity
>()
.
eq
(
FileRecordEntity:
:
getFileId
,
fileId
));
.
eq
(
FileRecordEntity:
:
getFileId
,
fileId
));
}
public
List
<
FileRecordEntity
>
queryByIds
(
List
<
String
>
fileIds
)
{
return
fileRecordMapper
.
selectList
(
new
LambdaQueryWrapper
<
FileRecordEntity
>()
.
in
(
FileRecordEntity:
:
getFileId
,
fileIds
));
.
in
(
FileRecordEntity:
:
getFileId
,
fileIds
));
}
public
FileRecordEntity
queryByOssKey
(
String
fileKey
)
{
return
fileRecordMapper
.
selectOne
(
new
LambdaQueryWrapper
<
FileRecordEntity
>().
eq
(
FileRecordEntity:
:
getFileOssKey
,
fileKey
));
return
fileRecordMapper
.
selectOne
(
new
LambdaQueryWrapper
<
FileRecordEntity
>().
eq
(
FileRecordEntity:
:
getFileOssKey
,
fileKey
));
}
...
...
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