Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
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
李丛阳
education
Commits
382986fd
Commit
382986fd
authored
Dec 30, 2019
by
zhangqingle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加图片损坏验证
parent
ae9dbe77
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
2 deletions
+59
-2
BChapterServiceImpl.java
...t/business/bchapter/service/impl/BChapterServiceImpl.java
+5
-1
BFileController.java
...rg/rcisoft/business/bfile/controller/BFileController.java
+10
-0
BFileService.java
...java/org/rcisoft/business/bfile/service/BFileService.java
+2
-0
BFileServiceImpl.java
...rcisoft/business/bfile/service/impl/BFileServiceImpl.java
+1
-1
FileReadableUtil.java
src/main/java/org/rcisoft/core/util/FileReadableUtil.java
+41
-0
No files found.
src/main/java/org/rcisoft/business/bchapter/service/impl/BChapterServiceImpl.java
View file @
382986fd
...
...
@@ -666,7 +666,11 @@ public class BChapterServiceImpl implements BChapterService {
LogUtil
.
fileChangeLog
(
"------------------下载-------------------------"
+
fileOld
);
String
downLoadName
=
downLoadFile
(
bFile
,
file
,
filePath
);
LogUtil
.
fileChangeLog
(
"------------------判断可读-------------------------"
+
fileOld
);
FileReadableUtil
.
fileReadable
(
filePath
+
File
.
separator
+
downLoadName
,
fileMaxSize
,
fileMaxPages
);
if
(
"7"
.
equals
(
bFile
.
getType
())
||
"8"
.
equals
(
bFile
.
getType
())
||
"9"
.
equals
(
bFile
.
getType
())
||
"10"
.
equals
(
bFile
.
getType
())){
FileReadableUtil
.
imgReadable
(
filePath
+
File
.
separator
+
downLoadName
);
}
else
{
FileReadableUtil
.
fileReadable
(
filePath
+
File
.
separator
+
downLoadName
,
fileMaxSize
,
fileMaxPages
);
}
}
return
flag
;
}
...
...
src/main/java/org/rcisoft/business/bfile/controller/BFileController.java
View file @
382986fd
...
...
@@ -64,5 +64,15 @@ public class BFileController extends PaginationController<BFile> {
MessageConstant
.
MESSAGE_ALERT_ERROR
,
message
);
}
@ApiOperation
(
value
=
"403 判断图片是否可读"
,
notes
=
"判断图片是否可读"
)
@PostMapping
(
value
=
"/fileReadable"
)
public
Result
imgReadable
(
CurUser
curUser
,
MultipartFile
file
)
{
int
result
=
bFileService
.
imgReadable
(
file
);
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
result
);
}
}
src/main/java/org/rcisoft/business/bfile/service/BFileService.java
View file @
382986fd
...
...
@@ -54,6 +54,8 @@ public interface BFileService {
String
deleteFile
();
int
imgReadable
(
MultipartFile
file
);
public
BFile
queryFileUrlByChapterId
(
String
chapterId
);
...
...
src/main/java/org/rcisoft/business/bfile/service/impl/BFileServiceImpl.java
View file @
382986fd
This diff is collapsed.
Click to expand it.
src/main/java/org/rcisoft/core/util/FileReadableUtil.java
View file @
382986fd
...
...
@@ -11,8 +11,12 @@ import org.apache.poi.xslf.usermodel.XMLSlideShow;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.result.ResultServiceEnums
;
import
org.springframework.web.multipart.MultipartFile
;
import
ucar.nc2.util.IO
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
@Slf4j
...
...
@@ -199,4 +203,41 @@ public class FileReadableUtil {
return
file
;
}
public
static
int
imgReadable
(
MultipartFile
f
){
try
{
// File f = new File(path);
// FileInputStream fi = new FileInputStream(f);
FileInputStream
fi
=
(
FileInputStream
)
f
.
getInputStream
();
try
{
BufferedImage
sourceImg
=
ImageIO
.
read
(
fi
);
//判断图片是否损坏
int
picWidth
=
sourceImg
.
getWidth
();
//确保图片是正确的(正确的图片可以取得宽度)
}
catch
(
Exception
e
)
{
fi
.
close
();
//关闭IO流才能操作图片
throw
new
ServiceException
(
ResultServiceEnums
.
FILE_UNREADABLE
);
}
finally
{
fi
.
close
();
//最后一定要关闭IO流
}
}
catch
(
IOException
e
)
{
throw
new
ServiceException
(
"读取io流失败"
);
}
return
1
;
}
public
static
void
imgReadable
(
String
path
){
try
{
File
f
=
new
File
(
path
);
FileInputStream
fi
=
new
FileInputStream
(
f
);
try
{
BufferedImage
sourceImg
=
ImageIO
.
read
(
fi
);
//判断图片是否损坏
int
picWidth
=
sourceImg
.
getWidth
();
//确保图片是正确的(正确的图片可以取得宽度)
}
catch
(
Exception
e
)
{
fi
.
close
();
//关闭IO流才能操作图片
throw
new
ServiceException
(
ResultServiceEnums
.
FILE_UNREADABLE
);
}
finally
{
fi
.
close
();
//最后一定要关闭IO流
}
}
catch
(
IOException
e
)
{
throw
new
ServiceException
(
"读取io流失败"
);
}
}
}
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