Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
chnmuseum-party
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liqin
chnmuseum-party
Commits
2a329dd3
Commit
2a329dd3
authored
Mar 20, 2021
by
liqin
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
5ce9da30
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
390 additions
and
750 deletions
+390
-750
pom.xml
pom.xml
+1
-6
FastDFSUtils.java
...cn/wisenergy/chnmuseum/party/common/dfs/FastDFSUtils.java
+60
-206
FdfsUtil.java
...ava/cn/wisenergy/chnmuseum/party/common/dfs/FdfsUtil.java
+0
-51
FileTypeUtil.java
...cn/wisenergy/chnmuseum/party/common/dfs/FileTypeUtil.java
+0
-228
StorePath1.java
...a/cn/wisenergy/chnmuseum/party/common/dfs/StorePath1.java
+0
-127
MyLogicSqlInjector.java
...gy/chnmuseum/party/common/mybatis/MyLogicSqlInjector.java
+1
-1
FileTypeUtil.java
...n/wisenergy/chnmuseum/party/common/util/FileTypeUtil.java
+216
-0
FileUtil.java
...va/cn/wisenergy/chnmuseum/party/common/util/FileUtil.java
+4
-4
UeditorServiceFastdfsImpl.java
...nmuseum/party/service/impl/UeditorServiceFastdfsImpl.java
+88
-94
AssetController.java
...nergy/chnmuseum/party/web/controller/AssetController.java
+2
-2
PicUploadController.java
...y/chnmuseum/party/web/controller/PicUploadController.java
+3
-18
BaseState.java
src/main/java/com/baidu/ueditor/define/BaseState.java
+2
-1
UEImageHunter.java
src/main/java/com/baidu/ueditor/extend/UEImageHunter.java
+8
-10
UeditorService.java
src/main/java/com/baidu/ueditor/extend/UeditorService.java
+5
-2
No files found.
pom.xml
View file @
2a329dd3
...
@@ -109,11 +109,6 @@
...
@@ -109,11 +109,6 @@
<version>
1.2.75
</version>
<version>
1.2.75
</version>
</dependency>
</dependency>
<!-- FastDFS -->
<!-- FastDFS -->
<dependency>
<groupId>
net.oschina.zcx7878
</groupId>
<artifactId>
fastdfs-client-java
</artifactId>
<version>
1.27.0.0
</version>
</dependency>
<dependency>
<dependency>
<groupId>
com.github.tobato
</groupId>
<groupId>
com.github.tobato
</groupId>
<artifactId>
fastdfs-client
</artifactId>
<artifactId>
fastdfs-client
</artifactId>
...
@@ -159,7 +154,7 @@
...
@@ -159,7 +154,7 @@
<dependency>
<dependency>
<groupId>
com.github.xiaoymin
</groupId>
<groupId>
com.github.xiaoymin
</groupId>
<artifactId>
knife4j-spring-boot-starter
</artifactId>
<artifactId>
knife4j-spring-boot-starter
</artifactId>
<version>
2.0.
4
</version>
<version>
2.0.
8
</version>
<exclusions>
<exclusions>
<exclusion>
<exclusion>
<artifactId>
guava
</artifactId>
<artifactId>
guava
</artifactId>
...
...
src/main/java/cn/wisenergy/chnmuseum/party/common/dfs/FastDFSUtils.java
View file @
2a329dd3
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
dfs
;
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
dfs
;
import
cn.wisenergy.chnmuseum.party.common.mvc.InterfaceException
;
import
cn.wisenergy.chnmuseum.party.common.util.FileTypeUtil
;
import
cn.wisenergy.chnmuseum.party.common.util.FileUtil
;
import
com.github.tobato.fastdfs.domain.fdfs.StorePath
;
import
com.github.tobato.fastdfs.domain.fdfs.ThumbImageConfig
;
import
com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray
;
import
com.github.tobato.fastdfs.service.FastFileStorageClient
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.csource.common.NameValuePair
;
import
org.csource.fastdfs.UploadCallback
;
import
org.csource.fastdfs.*
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
import
java.io.ByteArrayInputStream
;
import
java.util.Date
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
/**
* ueditor
*/
@Component
@Component
@Slf4j
public
class
FastDFSUtils
{
public
class
FastDFSUtils
{
private
static
String
dfsFileAccessBasePath
;
private
static
String
dfsFileAccessBasePath
;
private
static
ThumbImageConfig
imageConfig
;
private
static
FastFileStorageClient
storageClient
;
@Value
(
"${dfsFileAccessBasePath:#{null}}"
)
@Value
(
"${dfsFileAccessBasePath:#{null}}"
)
public
void
setDfsFileAccessBasePath
(
String
dfsFileAccessBasePath
)
{
public
void
setDfsFileAccessBasePath
(
String
dfsFileAccessBasePath
)
{
FastDFSUtils
.
dfsFileAccessBasePath
=
dfsFileAccessBasePath
;
FastDFSUtils
.
dfsFileAccessBasePath
=
dfsFileAccessBasePath
;
}
}
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FastDFSUtils
.
class
);
@Resource
private
ThumbImageConfig
thumbImageConfig
;
@Resource
private
FastFileStorageClient
fastFileStorageClient
;
private
static
boolean
isInit
=
false
;
@PostConstruct
public
void
init
()
{
private
static
void
init
()
throws
Exception
{
FastDFSUtils
.
storageClient
=
fastFileStorageClient
;
Properties
props
=
new
Properties
();
FastDFSUtils
.
imageConfig
=
thumbImageConfig
;
final
InputStream
in
=
new
ClassPathResource
(
"fastdfs-client.properties"
).
getInputStream
();
props
.
load
(
in
);
ClientGlobal
.
initByProperties
(
props
);
}
}
private
static
TrackerClient
getTrackerClient
()
throws
Exception
{
/**
if
(!
isInit
)
{
* 字节流方式上传
init
();
*/
isInit
=
true
;
public
static
Map
<
String
,
Object
>
uploadImage
(
InputStream
inputStream
,
long
fileSize
,
String
fileName
)
{
boolean
isImage
=
FileTypeUtil
.
isImageByExtension
(
fileName
);
if
(
isImage
)
{
String
mimeType
=
FileUtil
.
getMimeType
(
fileName
);
final
String
storePath
=
FastDFSUtils
.
uploadFile
(
inputStream
,
fileSize
,
fileName
);
Map
<
String
,
Object
>
uploadResult
=
new
HashMap
<>();
uploadResult
.
put
(
"url"
,
dfsFileAccessBasePath
+
"/"
+
storePath
);
uploadResult
.
put
(
"status"
,
true
);
uploadResult
.
put
(
"message"
,
"文件上传成功!"
);
uploadResult
.
put
(
"title"
,
fileName
);
uploadResult
.
put
(
"mimeType"
,
mimeType
);
uploadResult
.
put
(
"size"
,
fileSize
);
return
uploadResult
;
}
}
return
new
TrackerClient
();
throw
new
InterfaceException
(
"400"
,
"文件不是图片类型"
);
}
private
static
TrackerServer
getTrackerServer
()
throws
Exception
{
return
getTrackerClient
().
getConnection
();
}
}
p
rivate
static
StorageClient
getStorageClient
()
throws
Exception
{
p
ublic
static
String
uploadFile
(
InputStream
inputStream
,
long
size
,
String
fileName
)
{
TrackerServer
trackerServer
=
getTrackerServer
(
);
final
StorePath
storePath
=
storageClient
.
uploadFile
(
inputStream
,
size
,
FilenameUtils
.
getExtension
(
fileName
),
null
);
return
new
StorageClient
(
trackerServer
,
null
);
return
dfsFileAccessBasePath
+
"/"
+
storePath
.
getFullPath
(
);
}
}
/**
/**
*
文件方式上传
*
下载文件(字节数组)
*/
*/
public
static
Map
<
String
,
Object
>
uploadFile
(
File
file
)
{
public
static
byte
[]
downloadFile
(
String
fileUrl
)
{
String
fileName
=
file
.
getName
(
);
String
group
=
fileUrl
.
substring
(
0
,
fileUrl
.
indexOf
(
"/"
)
);
byte
[]
fileBuff
=
FileUtil
.
getBytes
(
file
);
String
path
=
fileUrl
.
substring
(
fileUrl
.
indexOf
(
"/"
)
+
1
);
return
uploadFile
(
fileBuff
,
fileName
);
return
storageClient
.
downloadFile
(
group
,
path
,
new
DownloadByteArray
()
);
}
}
/**
/**
*
是否是图片
*
删除文件
*/
*/
private
static
boolean
isImage
(
String
fileName
)
{
public
static
byte
[]
deleteFile
(
String
fileUrl
)
{
return
FileTypeUtil
.
isImageByExtension
(
fileName
);
String
group
=
fileUrl
.
substring
(
0
,
fileUrl
.
indexOf
(
"/"
));
String
path
=
fileUrl
.
substring
(
fileUrl
.
indexOf
(
"/"
)
+
1
);
return
storageClient
.
downloadFile
(
group
,
path
,
new
DownloadByteArray
());
}
}
/**
private
static
int
[]
getImageInfo
(
byte
[]
bytes
)
{
* 字节流方式上传
*/
public
static
Map
<
String
,
Object
>
uploadFile
(
byte
[]
fileBuff
,
String
fileName
)
{
String
originalFileName
=
FilenameUtils
.
getName
(
fileName
);
// 文件名
String
fileExtName
=
FilenameUtils
.
getExtension
(
originalFileName
);
// 文件后缀名
long
length
=
fileBuff
.
length
;
// 字节
boolean
isImage
=
isImage
(
originalFileName
);
String
mimeType
=
FileUtil
.
getMimeType
(
fileName
);
int
width
=
0
;
int
height
=
0
;
if
(
isImage
)
{
int
[]
imageInfo
=
getImageInfo
(
fileBuff
);
width
=
imageInfo
[
0
];
height
=
imageInfo
[
1
];
}
NameValuePair
[]
metaList
=
new
NameValuePair
[]{
new
NameValuePair
(
"fileName"
,
fileName
),
new
NameValuePair
(
"isImage"
,
isImage
+
""
),
new
NameValuePair
(
"mimeType"
,
mimeType
),
new
NameValuePair
(
"width"
,
width
+
""
),
new
NameValuePair
(
"height"
,
height
+
""
),
new
NameValuePair
(
"author"
,
"FastdfsUtils"
)};
boolean
status
=
false
;
String
message
=
"文件上传失败!"
;
logger
.
info
(
"startTIme:"
+
(
new
Date
().
getMinutes
()));
String
[]
responseData
=
storeFile
(
fileBuff
,
fileExtName
,
metaList
);
logger
.
info
(
"startTIme:"
+
(
new
Date
().
getMinutes
()));
Map
<
String
,
Object
>
uploadResult
=
new
HashMap
<
String
,
Object
>();
if
(
responseData
!=
null
)
{
status
=
true
;
message
=
"文件上传成功!"
;
uploadResult
.
put
(
"isImage"
,
isImage
);
if
(
isImage
)
{
uploadResult
.
put
(
"width"
,
width
);
uploadResult
.
put
(
"height"
,
height
);
}
uploadResult
.
put
(
"groupName"
,
responseData
[
0
]);
uploadResult
.
put
(
"storageFileName"
,
responseData
[
1
]);
uploadResult
.
put
(
"link"
,
responseData
[
0
]
+
"/"
+
responseData
[
1
]);
// 文件访问链接
}
uploadResult
.
put
(
"status"
,
status
);
uploadResult
.
put
(
"message"
,
message
);
uploadResult
.
put
(
"fileName"
,
fileName
);
uploadResult
.
put
(
"mimeType"
,
mimeType
);
uploadResult
.
put
(
"length"
,
length
);
return
uploadResult
;
}
private
static
int
[]
getImageInfo
(
byte
[]
fileBuff
)
{
try
{
try
{
// File转为BufferedImage
ByteArrayInputStream
baos
=
new
ByteArrayInputStream
(
bytes
);
// BufferedImage buff = ImageIO.read(new
BufferedImage
image
=
ImageIO
.
read
(
baos
);
// FileImageInputStream(file));
// BufferedImage buff = ImageIO.read(file);
// byte[]转为BufferedImage
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
fileBuff
);
// 将byte[]作为输入流;
BufferedImage
image
=
ImageIO
.
read
(
in
);
// 将in作为输入流,读取图片存入image中,而这里in可以为ByteArrayInputStream();
int
width
=
image
.
getWidth
();
int
width
=
image
.
getWidth
();
int
height
=
image
.
getHeight
();
int
height
=
image
.
getHeight
();
return
new
int
[]{
width
,
height
};
return
new
int
[]{
width
,
height
};
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
ger
.
error
(
"FastdfsUtils.getImageInfo时发生异常
:"
,
e
);
log
.
error
(
"FastDFSUtils.getImageInfo() error
:"
,
e
);
}
}
return
new
int
[]{
0
,
0
};
return
new
int
[]{
0
,
0
};
}
}
private
static
String
[]
storeFile
(
byte
[]
fileBuff
,
String
fileExtName
,
NameValuePair
[]
metaList
)
{
String
[]
responseData
=
null
;
try
{
StorageClient
storageClient
=
getStorageClient
();
responseData
=
storageClient
.
upload_file
(
fileBuff
,
fileExtName
.
toLowerCase
(),
metaList
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"FastdfsUtils.storeFile时发生异常:"
,
e
);
}
return
responseData
;
}
public
static
String
[]
uploadPic
(
String
path
,
String
fileName
,
long
size
)
{
String
[]
fileIds
=
null
;
try
{
// ClientGloble 读配置文件
// 老大客户端
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
StorageServer
storageServer
=
null
;
StorageClient
storageClient
=
new
StorageClient
(
trackerServer
,
storageServer
);
String
extName
=
FilenameUtils
.
getExtension
(
fileName
);
NameValuePair
[]
meta_list
=
new
NameValuePair
[
3
];
meta_list
[
0
]
=
new
NameValuePair
(
"fileName"
,
fileName
);
meta_list
[
1
]
=
new
NameValuePair
(
"fileExt"
,
extName
);
meta_list
[
2
]
=
new
NameValuePair
(
"fileSize"
,
String
.
valueOf
(
size
));
// http://172.16.15.244:8081/group1/M00/00/00/rBAP9FfFG62AZsuBAADeW7MfEHA287.png
// group1/M00/00/01/wKjIgFWOYc6APpjAAAD-qk29i78248.jpg
fileIds
=
storageClient
.
upload_file
(
path
,
extName
,
meta_list
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
fileIds
;
}
public
static
String
uploadInputStream
(
InputStream
inStream
,
String
fileName
,
long
size
)
{
String
[]
fileIds
;
try
{
String
extName
=
FilenameUtils
.
getExtension
(
fileName
);
NameValuePair
[]
meta_list
=
new
NameValuePair
[
3
];
meta_list
[
0
]
=
new
NameValuePair
(
"fileName"
,
fileName
);
meta_list
[
1
]
=
new
NameValuePair
(
"fileExt"
,
extName
);
meta_list
[
2
]
=
new
NameValuePair
(
"fileSize"
,
String
.
valueOf
(
size
));
fileIds
=
getStorageClient
().
upload_file
(
null
,
size
,
new
FastDFSUtils
.
UploadFileSender
(
inStream
),
extName
,
meta_list
);
return
dfsFileAccessBasePath
+
"/"
+
fileIds
[
0
]
+
"/"
+
fileIds
[
1
];
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
String
uploadPic
(
byte
[]
pic
,
String
fileName
,
long
size
)
{
String
[]
fileIds
=
null
;
try
{
// ClientGloble 读配置文件
// 老客户端
TrackerClient
trackerClient
=
new
TrackerClient
();
TrackerServer
trackerServer
=
trackerClient
.
getConnection
();
StorageServer
storageServer
=
null
;
StorageClient
storageClient
=
new
StorageClient
(
trackerServer
,
storageServer
);
String
extName
=
FilenameUtils
.
getExtension
(
fileName
);
// 设置图片meta信息
NameValuePair
[]
meta_list
=
new
NameValuePair
[
3
];
meta_list
[
0
]
=
new
NameValuePair
(
"fileName"
,
fileName
);
meta_list
[
1
]
=
new
NameValuePair
(
"fileExt"
,
extName
);
meta_list
[
2
]
=
new
NameValuePair
(
"fileSize"
,
String
.
valueOf
(
size
));
// 上传且返回path
fileIds
=
storageClient
.
upload_file
(
pic
,
extName
,
meta_list
);
return
fileIds
[
0
]
+
"/"
+
fileIds
[
1
];
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
boolean
deletePic
(
String
fileUrl
)
{
try
{
TrackerClient
tracker
=
new
TrackerClient
();
TrackerServer
trackerServer
=
tracker
.
getConnection
();
StorageServer
storageServer
=
null
;
StorageClient
storageClient
=
new
StorageClient
(
trackerServer
,
storageServer
);
StorePath1
storePath1
=
StorePath1
.
praseFromUrl
(
fileUrl
);
int
i
=
storageClient
.
delete_file
(
storePath1
.
getGroup
(),
storePath1
.
getPath
());
System
.
out
.
println
(
i
==
0
?
"删除成功"
:
"删除失败:"
+
i
);
return
i
==
0
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
public
static
String
deletePic
(
String
[]
fileIds
)
{
try
{
int
i
=
getStorageClient
().
delete_file
(
fileIds
[
0
],
fileIds
[
1
]);
System
.
out
.
println
(
i
==
0
?
"删除成功"
:
"删除失败:"
+
i
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
fileIds
[
1
];
}
private
static
class
UploadFileSender
implements
UploadCallback
{
private
static
class
UploadFileSender
implements
UploadCallback
{
private
final
InputStream
is
;
private
final
InputStream
is
;
...
...
src/main/java/cn/wisenergy/chnmuseum/party/common/dfs/FdfsUtil.java
deleted
100644 → 0
View file @
5ce9da30
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
dfs
;
import
com.github.tobato.fastdfs.domain.fdfs.StorePath
;
import
com.github.tobato.fastdfs.domain.fdfs.ThumbImageConfig
;
import
com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray
;
import
com.github.tobato.fastdfs.service.FastFileStorageClient
;
import
org.apache.commons.io.FilenameUtils
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
@Component
public
class
FdfsUtil
{
@Resource
private
FastFileStorageClient
fastFileStorageClient
;
@Resource
private
ThumbImageConfig
thumbImageConfig
;
/**
* 上传文件
*
* @param file 文件对象
* @return storePath 文件在服务器中的存储路径 group1/M00/00/08/rBEAA2A_Ci2AU9pHAAYlnPgRYiA554.jpg
* @throws IOException
*/
public
String
uploadFile
(
MultipartFile
file
)
throws
IOException
{
// StorePath storePath = fastFileStorageClient.uploadFile("aifruit", //默认都是放在aifruit分组group
StorePath
storePath
=
fastFileStorageClient
.
uploadFile
(
file
.
getInputStream
(),
file
.
getSize
(),
FilenameUtils
.
getExtension
(
file
.
getOriginalFilename
()),
null
);
return
storePath
.
getFullPath
();
//返回完整的图片存放路径(含group)
}
/**
* 下载文件(文件字节)
*
* @param fileUrl 文件服务器存储路径 group1/M00/00/08/rBEAA2A_Ci2AU9pHAAYlnPgRYiA554.jpg
* @return byte[] 文件字节
* @throws IOException
*/
public
byte
[]
downloadFileByByte
(
String
fileUrl
)
{
String
group
=
fileUrl
.
substring
(
0
,
fileUrl
.
indexOf
(
"/"
));
String
path
=
fileUrl
.
substring
(
fileUrl
.
indexOf
(
"/"
)
+
1
);
return
fastFileStorageClient
.
downloadFile
(
group
,
path
,
new
DownloadByteArray
());
}
}
src/main/java/cn/wisenergy/chnmuseum/party/common/dfs/FileTypeUtil.java
deleted
100644 → 0
View file @
5ce9da30
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
dfs
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageReader
;
import
javax.imageio.stream.ImageInputStream
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.commons.lang3.StringUtils
;
public
class
FileTypeUtil
{
private
final
static
Map
<
String
,
String
>
FILE_TYPE_MAP
=
new
HashMap
<
String
,
String
>();
private
final
static
List
<
String
>
imageAllowFiles
=
Arrays
.
asList
(
new
String
[]
{
"png"
,
"jpg"
,
"jpeg"
,
"gif"
,
"bmp"
});
/* 允许上传的图片格式 */
static
{
getAllFileType
();
// 初始化文件类型信息
}
/**
* <p>
* Discription:[getAllFileType,常见文件头信息] 注:TXT文件没有文件头
* </p>
*/
private
static
void
getAllFileType
()
{
FILE_TYPE_MAP
.
put
(
"jpg"
,
"FFD8FF"
);
// JPEG (jpg)
FILE_TYPE_MAP
.
put
(
"png"
,
"89504E47"
);
// PNG (png)
FILE_TYPE_MAP
.
put
(
"gif"
,
"47494638"
);
// GIF (gif)
FILE_TYPE_MAP
.
put
(
"tif"
,
"49492A00"
);
// TIFF (tif)
FILE_TYPE_MAP
.
put
(
"bmp"
,
"424D"
);
// Windows Bitmap (bmp)
FILE_TYPE_MAP
.
put
(
"dwg"
,
"41433130"
);
// CAD (dwg)
FILE_TYPE_MAP
.
put
(
"html"
,
"68746D6C3E"
);
// HTML (html)
FILE_TYPE_MAP
.
put
(
"rtf"
,
"7B5C727466"
);
// Rich Text Format (rtf)
FILE_TYPE_MAP
.
put
(
"xml"
,
"3C3F786D6C"
);
FILE_TYPE_MAP
.
put
(
"zip"
,
"504B0304"
);
FILE_TYPE_MAP
.
put
(
"rar"
,
"52617221"
);
FILE_TYPE_MAP
.
put
(
"psd"
,
"38425053"
);
// Photoshop (psd)
FILE_TYPE_MAP
.
put
(
"eml"
,
"44656C69766572792D646174653A"
);
// Email
// [thorough
// only]
// (eml)
FILE_TYPE_MAP
.
put
(
"dbx"
,
"CFAD12FEC5FD746F"
);
// Outlook Express (dbx)
FILE_TYPE_MAP
.
put
(
"pst"
,
"2142444E"
);
// Outlook (pst)
FILE_TYPE_MAP
.
put
(
"xls"
,
"D0CF11E0"
);
// MS Word
FILE_TYPE_MAP
.
put
(
"doc"
,
"D0CF11E0"
);
// MS Excel 注意:word 和 excel的文件头一样
FILE_TYPE_MAP
.
put
(
"mdb"
,
"5374616E64617264204A"
);
// MS Access (mdb)
FILE_TYPE_MAP
.
put
(
"wpd"
,
"FF575043"
);
// WordPerfect (wpd)
FILE_TYPE_MAP
.
put
(
"eps"
,
"252150532D41646F6265"
);
FILE_TYPE_MAP
.
put
(
"ps"
,
"252150532D41646F6265"
);
FILE_TYPE_MAP
.
put
(
"pdf"
,
"255044462D312E"
);
// Adobe Acrobat (pdf)
FILE_TYPE_MAP
.
put
(
"qdf"
,
"AC9EBD8F"
);
// Quicken (qdf)
FILE_TYPE_MAP
.
put
(
"pwl"
,
"E3828596"
);
// Windows Password (pwl)
FILE_TYPE_MAP
.
put
(
"wav"
,
"57415645"
);
// Wave (wav)
FILE_TYPE_MAP
.
put
(
"avi"
,
"41564920"
);
FILE_TYPE_MAP
.
put
(
"ram"
,
"2E7261FD"
);
// Real Audio (ram)
FILE_TYPE_MAP
.
put
(
"rm"
,
"2E524D46"
);
// Real Media (rm)
FILE_TYPE_MAP
.
put
(
"mpg"
,
"000001BA"
);
//
FILE_TYPE_MAP
.
put
(
"mov"
,
"6D6F6F76"
);
// Quicktime (mov)
FILE_TYPE_MAP
.
put
(
"asf"
,
"3026B2758E66CF11"
);
// Windows Media (asf)
FILE_TYPE_MAP
.
put
(
"mid"
,
"4D546864"
);
// MIDI (mid)
}
/**
* <p>
* Discription:[getFileTypeByStream]
* </p>
*/
public
final
static
String
getFileTypeByStream
(
byte
[]
b
)
{
String
filetypeHex
=
String
.
valueOf
(
getFileHexString
(
b
));
Iterator
<
Entry
<
String
,
String
>>
entryiterator
=
FILE_TYPE_MAP
.
entrySet
().
iterator
();
while
(
entryiterator
.
hasNext
())
{
Entry
<
String
,
String
>
entry
=
entryiterator
.
next
();
String
fileTypeHexValue
=
entry
.
getValue
();
if
(
filetypeHex
.
toUpperCase
().
startsWith
(
fileTypeHexValue
))
{
return
entry
.
getKey
();
}
}
return
null
;
}
/**
* <p>
* Discription:[getFileByFile,获取文件类型,包括图片,若格式不是已配置的,则返回null]
* </p>
*/
public
final
static
String
getFileTypeByFile
(
File
file
)
{
String
fileType
=
null
;
byte
[]
b
=
new
byte
[
50
];
try
{
InputStream
is
=
new
FileInputStream
(
file
);
is
.
read
(
b
);
fileType
=
getFileTypeByStream
(
b
);
is
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
fileType
;
}
/**
* <p>
* Discription:[getFileHexString]
* </p>
*/
public
final
static
String
getFileHexString
(
byte
[]
b
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
if
(
b
==
null
||
b
.
length
<=
0
)
{
return
null
;
}
for
(
int
i
=
0
;
i
<
b
.
length
;
i
++)
{
int
v
=
b
[
i
]
&
0xFF
;
String
hv
=
Integer
.
toHexString
(
v
);
if
(
hv
.
length
()
<
2
)
{
stringBuilder
.
append
(
0
);
}
stringBuilder
.
append
(
hv
);
}
return
stringBuilder
.
toString
();
}
/**
* <p>
* Discription:[getImageFileType,获取图片文件实际类型,若不是图片则返回null]
* </p>
*/
public
final
static
String
getImageFileType
(
File
f
)
{
if
(
isImage
(
f
))
{
try
{
ImageInputStream
iis
=
ImageIO
.
createImageInputStream
(
f
);
Iterator
<
ImageReader
>
iter
=
ImageIO
.
getImageReaders
(
iis
);
if
(!
iter
.
hasNext
())
{
return
null
;
}
ImageReader
reader
=
iter
.
next
();
iis
.
close
();
return
reader
.
getFormatName
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
return
null
;
}
/**
* 只根据后缀名判断是否为图片
*
* @param file
* @return
*/
public
static
final
boolean
isImage
(
File
file
)
{
return
isImage
(
file
,
true
);
}
/**
* <p>
* Discription:[isImage,判断文件是否为图片]
* </p>
*
* @param file
* 源文件
* @param onlyByExtension
* 是否值验证后缀名
* @return true 是 | false 否
*/
public
static
final
boolean
isImage
(
File
file
,
boolean
onlyByExtension
)
{
boolean
flag
=
false
;
try
{
boolean
allowFile
=
isImageByExtension
(
file
.
getName
());
if
(
onlyByExtension
)
{
flag
=
allowFile
;
}
else
{
if
(
allowFile
)
{
BufferedImage
bufreader
=
ImageIO
.
read
(
file
);
int
width
=
bufreader
.
getWidth
();
int
height
=
bufreader
.
getHeight
();
if
(
width
==
0
||
height
==
0
)
{
flag
=
false
;
}
else
{
flag
=
true
;
}
}
}
}
catch
(
IOException
e
)
{
flag
=
false
;
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
flag
=
false
;
e
.
printStackTrace
();
}
return
flag
;
}
/**
* 只通过后缀名判断是否为图片
*
* @param fileName
* @return
*/
public
static
final
boolean
isImageByExtension
(
String
fileName
)
{
boolean
flag
=
false
;
String
fileExtName
=
FilenameUtils
.
getExtension
(
fileName
);
if
(
StringUtils
.
isNotBlank
(
fileExtName
))
{
flag
=
imageAllowFiles
.
contains
(
fileExtName
.
toLowerCase
());
}
return
flag
;
}
}
src/main/java/cn/wisenergy/chnmuseum/party/common/dfs/StorePath1.java
deleted
100644 → 0
View file @
5ce9da30
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
dfs
;
import
cn.wisenergy.chnmuseum.party.common.exception.FdfsUnsupportStorePathException
;
import
org.apache.commons.lang3.Validate
;
/**
* 存储文件的路径信息
*
* @author yuqih
*
*/
public
class
StorePath1
{
private
String
group
;
private
String
path
;
/** 解析路径 */
private
static
final
String
SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR
=
"/"
;
/** group */
private
static
final
String
SPLIT_GROUP_NAME
=
"group"
;
/**
* 存储文件路径
*/
public
StorePath1
()
{
}
/**
* 存储文件路径
*
* @param group
* @param path
*/
public
StorePath1
(
String
group
,
String
path
)
{
super
();
this
.
group
=
group
;
this
.
path
=
path
;
}
/**
* @return the group
*/
public
String
getGroup
()
{
return
group
;
}
/**
* @param group
* the group to set
*/
public
void
setGroup
(
String
group
)
{
this
.
group
=
group
;
}
/**
* @return the path
*/
public
String
getPath
()
{
return
path
;
}
/**
* @param path
* the path to set
*/
public
void
setPath
(
String
path
)
{
this
.
path
=
path
;
}
/**
* 获取文件全路径
*
* @return
*/
public
String
getFullPath
()
{
return
this
.
group
.
concat
(
SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR
).
concat
(
this
.
path
);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"StorePath [group="
+
group
+
", path="
+
path
+
"]"
;
}
/**
* 从Url当中解析存储路径对象
*
* @param filePath
* 有效的路径样式为(group/path) 或者 (http://ip/group/path),路径地址必须包含group
* @return
*/
public
static
StorePath1
praseFromUrl
(
String
filePath
)
{
Validate
.
notNull
(
filePath
,
"解析文件路径不能为空"
);
// 获取group起始位置
int
groupStartPos
=
getGroupStartPos
(
filePath
);
String
groupAndPath
=
filePath
.
substring
(
groupStartPos
);
int
pos
=
groupAndPath
.
indexOf
(
SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR
);
if
((
pos
<=
0
)
||
(
pos
==
groupAndPath
.
length
()
-
1
))
{
throw
new
FdfsUnsupportStorePathException
(
"解析文件路径错误,有效的路径样式为(group/path) 而当前解析路径为"
.
concat
(
filePath
));
}
String
group
=
groupAndPath
.
substring
(
0
,
pos
);
String
path
=
groupAndPath
.
substring
(
pos
+
1
);
return
new
StorePath1
(
group
,
path
);
}
/**
* 获得group起始位置
*
* @param filePath
*/
private
static
int
getGroupStartPos
(
String
filePath
)
{
int
pos
=
filePath
.
indexOf
(
SPLIT_GROUP_NAME
);
if
((
pos
==
-
1
))
{
throw
new
FdfsUnsupportStorePathException
(
"解析文件路径错误,被解析路径url没有group,当前解析路径为"
.
concat
(
filePath
));
}
return
pos
;
}
}
\ No newline at end of file
src/main/java/cn/wisenergy/chnmuseum/party/common/mybatis/MyLogicSqlInjector.java
View file @
2a329dd3
...
@@ -11,7 +11,7 @@ import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFi
...
@@ -11,7 +11,7 @@ import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFi
import
java.util.List
;
import
java.util.List
;
/**
/**
* @author DannyLee
* @author Danny
Lee
* @description 自定义sql注入器·
* @description 自定义sql注入器·
* @date Created in 2020/3/6 16:10
* @date Created in 2020/3/6 16:10
*/
*/
...
...
src/main/java/cn/wisenergy/chnmuseum/party/common/util/FileTypeUtil.java
0 → 100644
View file @
2a329dd3
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
util
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageReader
;
import
javax.imageio.stream.ImageInputStream
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
import
java.util.*
;
import
java.util.Map.Entry
;
public
class
FileTypeUtil
{
private
static
final
Map
<
String
,
String
>
FILE_TYPE_MAP
=
new
HashMap
<>();
private
static
final
List
<
String
>
imageAllowFiles
=
Arrays
.
asList
(
"png"
,
"jpg"
,
"jpeg"
,
"gif"
,
"bmp"
);
/* 允许上传的图片格式 */
static
{
getAllFileType
();
// 初始化文件类型信息
}
/**
* <p>
* Discription:[getAllFileType,常见文件头信息] 注:TXT文件没有文件头
* </p>
*/
private
static
void
getAllFileType
()
{
FILE_TYPE_MAP
.
put
(
"jpg"
,
"FFD8FF"
);
// JPEG (jpg)
FILE_TYPE_MAP
.
put
(
"png"
,
"89504E47"
);
// PNG (png)
FILE_TYPE_MAP
.
put
(
"gif"
,
"47494638"
);
// GIF (gif)
FILE_TYPE_MAP
.
put
(
"tif"
,
"49492A00"
);
// TIFF (tif)
FILE_TYPE_MAP
.
put
(
"bmp"
,
"424D"
);
// Windows Bitmap (bmp)
FILE_TYPE_MAP
.
put
(
"dwg"
,
"41433130"
);
// CAD (dwg)
FILE_TYPE_MAP
.
put
(
"html"
,
"68746D6C3E"
);
// HTML (html)
FILE_TYPE_MAP
.
put
(
"rtf"
,
"7B5C727466"
);
// Rich Text Format (rtf)
FILE_TYPE_MAP
.
put
(
"xml"
,
"3C3F786D6C"
);
FILE_TYPE_MAP
.
put
(
"zip"
,
"504B0304"
);
FILE_TYPE_MAP
.
put
(
"rar"
,
"52617221"
);
FILE_TYPE_MAP
.
put
(
"psd"
,
"38425053"
);
// Photoshop (psd)
FILE_TYPE_MAP
.
put
(
"eml"
,
"44656C69766572792D646174653A"
);
// Email
// [thorough
// only]
// (eml)
FILE_TYPE_MAP
.
put
(
"dbx"
,
"CFAD12FEC5FD746F"
);
// Outlook Express (dbx)
FILE_TYPE_MAP
.
put
(
"pst"
,
"2142444E"
);
// Outlook (pst)
FILE_TYPE_MAP
.
put
(
"xls"
,
"D0CF11E0"
);
// MS Word
FILE_TYPE_MAP
.
put
(
"doc"
,
"D0CF11E0"
);
// MS Excel 注意:word 和 excel的文件头一样
FILE_TYPE_MAP
.
put
(
"mdb"
,
"5374616E64617264204A"
);
// MS Access (mdb)
FILE_TYPE_MAP
.
put
(
"wpd"
,
"FF575043"
);
// WordPerfect (wpd)
FILE_TYPE_MAP
.
put
(
"eps"
,
"252150532D41646F6265"
);
FILE_TYPE_MAP
.
put
(
"ps"
,
"252150532D41646F6265"
);
FILE_TYPE_MAP
.
put
(
"pdf"
,
"255044462D312E"
);
// Adobe Acrobat (pdf)
FILE_TYPE_MAP
.
put
(
"qdf"
,
"AC9EBD8F"
);
// Quicken (qdf)
FILE_TYPE_MAP
.
put
(
"pwl"
,
"E3828596"
);
// Windows Password (pwl)
FILE_TYPE_MAP
.
put
(
"wav"
,
"57415645"
);
// Wave (wav)
FILE_TYPE_MAP
.
put
(
"avi"
,
"41564920"
);
FILE_TYPE_MAP
.
put
(
"ram"
,
"2E7261FD"
);
// Real Audio (ram)
FILE_TYPE_MAP
.
put
(
"rm"
,
"2E524D46"
);
// Real Media (rm)
FILE_TYPE_MAP
.
put
(
"mpg"
,
"000001BA"
);
//
FILE_TYPE_MAP
.
put
(
"mov"
,
"6D6F6F76"
);
// Quicktime (mov)
FILE_TYPE_MAP
.
put
(
"asf"
,
"3026B2758E66CF11"
);
// Windows Media (asf)
FILE_TYPE_MAP
.
put
(
"mid"
,
"4D546864"
);
// MIDI (mid)
}
/**
* <p>
* Discription:[getFileTypeByStream]
* </p>
*/
public
final
static
String
getFileTypeByStream
(
byte
[]
b
)
{
String
filetypeHex
=
String
.
valueOf
(
getFileHexString
(
b
));
Iterator
<
Entry
<
String
,
String
>>
entryiterator
=
FILE_TYPE_MAP
.
entrySet
().
iterator
();
while
(
entryiterator
.
hasNext
())
{
Entry
<
String
,
String
>
entry
=
entryiterator
.
next
();
String
fileTypeHexValue
=
entry
.
getValue
();
if
(
filetypeHex
.
toUpperCase
().
startsWith
(
fileTypeHexValue
))
{
return
entry
.
getKey
();
}
}
return
null
;
}
/**
* <p>
* Discription:[getFileByFile,获取文件类型,包括图片,若格式不是已配置的,则返回null]
* </p>
*/
public
final
static
String
getFileTypeByFile
(
File
file
)
{
String
fileType
=
null
;
byte
[]
b
=
new
byte
[
50
];
try
{
InputStream
is
=
new
FileInputStream
(
file
);
is
.
read
(
b
);
fileType
=
getFileTypeByStream
(
b
);
is
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
fileType
;
}
/**
* <p>
* Discription:[getFileHexString]
* </p>
*/
public
final
static
String
getFileHexString
(
byte
[]
b
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
if
(
b
==
null
||
b
.
length
<=
0
)
{
return
null
;
}
for
(
int
i
=
0
;
i
<
b
.
length
;
i
++)
{
int
v
=
b
[
i
]
&
0xFF
;
String
hv
=
Integer
.
toHexString
(
v
);
if
(
hv
.
length
()
<
2
)
{
stringBuilder
.
append
(
0
);
}
stringBuilder
.
append
(
hv
);
}
return
stringBuilder
.
toString
();
}
/**
* <p>
* Discription:[getImageFileType,获取图片文件实际类型,若不是图片则返回null]
* </p>
*/
public
final
static
String
getImageFileType
(
File
f
)
{
if
(
isImage
(
f
))
{
try
{
ImageInputStream
iis
=
ImageIO
.
createImageInputStream
(
f
);
Iterator
<
ImageReader
>
iter
=
ImageIO
.
getImageReaders
(
iis
);
if
(!
iter
.
hasNext
())
{
return
null
;
}
ImageReader
reader
=
iter
.
next
();
iis
.
close
();
return
reader
.
getFormatName
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
return
null
;
}
/**
* 只根据后缀名判断是否为图片
*
* @param file
* @return
*/
public
static
final
boolean
isImage
(
File
file
)
{
return
isImage
(
file
,
true
);
}
/**
* <p>
* Discription:[isImage,判断文件是否为图片]
* </p>
*
* @param file 源文件
* @param onlyByExtension 是否值验证后缀名
* @return true 是 | false 否
*/
public
static
final
boolean
isImage
(
File
file
,
boolean
onlyByExtension
)
{
boolean
flag
=
false
;
try
{
boolean
allowFile
=
isImageByExtension
(
file
.
getName
());
if
(
onlyByExtension
)
{
flag
=
allowFile
;
}
else
{
if
(
allowFile
)
{
BufferedImage
bufreader
=
ImageIO
.
read
(
file
);
int
width
=
bufreader
.
getWidth
();
int
height
=
bufreader
.
getHeight
();
if
(
width
==
0
||
height
==
0
)
{
flag
=
false
;
}
else
{
flag
=
true
;
}
}
}
}
catch
(
IOException
e
)
{
flag
=
false
;
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
flag
=
false
;
e
.
printStackTrace
();
}
return
flag
;
}
/**
* 只通过后缀名判断是否为图片
*
* @param fileName
* @return
*/
public
static
final
boolean
isImageByExtension
(
String
fileName
)
{
boolean
flag
=
false
;
String
fileExtName
=
FilenameUtils
.
getExtension
(
fileName
);
if
(
StringUtils
.
isNotBlank
(
fileExtName
))
{
flag
=
imageAllowFiles
.
contains
(
fileExtName
.
toLowerCase
());
}
return
flag
;
}
}
src/main/java/cn/wisenergy/chnmuseum/party/common/
dfs
/FileUtil.java
→
src/main/java/cn/wisenergy/chnmuseum/party/common/
util
/FileUtil.java
View file @
2a329dd3
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
dfs
;
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
...
@@ -7,9 +10,6 @@ import java.io.IOException;
...
@@ -7,9 +10,6 @@ import java.io.IOException;
import
java.net.FileNameMap
;
import
java.net.FileNameMap
;
import
java.net.URLConnection
;
import
java.net.URLConnection
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
FileUtil
{
public
class
FileUtil
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FileUtil
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FileUtil
.
class
);
...
...
src/main/java/cn/wisenergy/chnmuseum/party/service/impl/UeditorServiceFastdfsImpl.java
View file @
2a329dd3
package
cn
.
wisenergy
.
chnmuseum
.
party
.
service
.
impl
;
package
cn
.
wisenergy
.
chnmuseum
.
party
.
service
.
impl
;
import
cn.wisenergy.chnmuseum.party.common.dfs.FastDFSUtils
;
import
com.baidu.ueditor.define.AppInfo
;
import
com.baidu.ueditor.define.AppInfo
;
import
com.baidu.ueditor.define.BaseState
;
import
com.baidu.ueditor.define.BaseState
;
import
com.baidu.ueditor.define.MultiState
;
import
com.baidu.ueditor.define.MultiState
;
import
com.baidu.ueditor.define.State
;
import
com.baidu.ueditor.define.State
;
import
com.baidu.ueditor.extend.UeditorService
;
import
com.baidu.ueditor.extend.UeditorService
;
import
cn.wisenergy.chnmuseum.party.common.dfs.FastDFSUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Map
;
import
java.util.Map
;
/**
/**
* UeditorService
实现 - Fastdfs
* UeditorService
的FastDFS实现
*/
*/
@Service
@Service
@ConfigurationProperties
public
class
UeditorServiceFastdfsImpl
implements
UeditorService
{
public
class
UeditorServiceFastdfsImpl
implements
UeditorService
{
@Value
(
"${dfsFileAccessBasePath}"
)
@Override
private
String
dfsFileAccessBasePath
;
public
com
.
baidu
.
ueditor
.
extend
.
MultipartFile
getMultipartFile
(
String
filedName
,
HttpServletRequest
request
)
{
com
.
baidu
.
ueditor
.
extend
.
MultipartFile
resultFile
=
null
;
@Override
try
{
public
com
.
baidu
.
ueditor
.
extend
.
MultipartFile
getMultipartFile
(
String
filedName
,
HttpServletRequest
request
)
{
MultipartHttpServletRequest
multipartHttpservletRequest
=
(
MultipartHttpServletRequest
)
request
;
com
.
baidu
.
ueditor
.
extend
.
MultipartFile
resultFile
=
null
;
MultipartFile
multipartFile
=
multipartHttpservletRequest
.
getFile
(
filedName
);
try
{
if
(
multipartFile
!=
null
&&
!
multipartFile
.
isEmpty
())
{
MultipartHttpServletRequest
multipartHttpservletRequest
=
(
MultipartHttpServletRequest
)
request
;
resultFile
=
new
com
.
baidu
.
ueditor
.
extend
.
StandardMultipartFile
(
filedName
,
multipartFile
.
getInputStream
(),
MultipartFile
multipartFile
=
multipartHttpservletRequest
.
getFile
(
filedName
);
multipartFile
.
getOriginalFilename
(),
multipartFile
.
getSize
());
if
(!
multipartFile
.
isEmpty
())
{
}
resultFile
=
new
com
.
baidu
.
ueditor
.
extend
.
StandardMultipartFile
(
filedName
,
multipartFile
.
getInputStream
(),
}
catch
(
IOException
e
)
{
multipartFile
.
getOriginalFilename
(),
multipartFile
.
getSize
());
e
.
printStackTrace
();
}
}
}
catch
(
IOException
e
)
{
return
resultFile
;
e
.
printStackTrace
();
}
}
return
resultFile
;
@Override
}
public
State
saveFileByInputStream
(
com
.
baidu
.
ueditor
.
extend
.
MultipartFile
multipartFile
,
long
maxSize
)
{
State
state
;
@Override
try
{
public
State
saveFileByInputStream
(
com
.
baidu
.
ueditor
.
extend
.
MultipartFile
multipartFile
,
long
maxSize
)
{
if
(
multipartFile
.
getSize
()
>
maxSize
)
{
State
state
=
null
;
return
new
BaseState
(
false
,
AppInfo
.
MAX_SIZE
);
try
{
}
if
(
multipartFile
.
getSize
()
>
maxSize
)
{
Map
<
String
,
Object
>
uploadResult
;
return
new
BaseState
(
false
,
AppInfo
.
MAX_SIZE
);
String
originalFileName
=
multipartFile
.
getOriginalFilename
();
}
uploadResult
=
FastDFSUtils
.
uploadImage
(
multipartFile
.
getInputStream
(),
multipartFile
.
getSize
(),
originalFileName
);
if
((
Boolean
)
uploadResult
.
get
(
"status"
))
{
Map
<
String
,
Object
>
uploadResult
=
null
;
state
=
new
BaseState
(
true
);
String
originalFileName
=
multipartFile
.
getOriginalFilename
();
state
.
putInfo
(
"size"
,
uploadResult
.
get
(
"size"
).
toString
());
uploadResult
=
FastDFSUtils
.
uploadFile
(
multipartFile
.
getBytes
(),
originalFileName
);
state
.
putInfo
(
"title"
,
uploadResult
.
get
(
"title"
).
toString
());
state
.
putInfo
(
"url"
,
uploadResult
.
get
(
"url"
).
toString
());
// // 文件新路径
return
state
;
// uploadResult = FastdfsUtil.uploadPic(multipartFile.getBytes(), multipartFile.getOriginalFilename(),
}
// multipartFile.getSize());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
((
Boolean
)
uploadResult
.
get
(
"status"
))
{
return
new
BaseState
(
false
,
AppInfo
.
IO_ERROR
);
state
=
new
BaseState
(
true
);
}
state
.
putInfo
(
"size"
,
uploadResult
.
get
(
"length"
).
toString
());
state
.
putInfo
(
"title"
,
uploadResult
.
get
(
"fileName"
).
toString
());
@Override
// state.putInfo("groupName",
public
State
saveBinaryFile
(
InputStream
inputStream
,
long
fileSize
,
String
fileName
)
{
// uploadResult.get("groupName").toString());
State
state
;
// state.putInfo("storageFileName",
// uploadResult.get("storageFileName").toString());
Map
<
String
,
Object
>
uploadResult
=
FastDFSUtils
.
uploadImage
(
inputStream
,
fileSize
,
fileName
);
state
.
putInfo
(
"url"
,
dfsFileAccessBasePath
+
"/"
+
uploadResult
.
get
(
"link"
).
toString
());
if
((
Boolean
)
uploadResult
.
get
(
"status"
))
{
state
=
new
BaseState
(
true
);
// 把上传的文件信息记入数据库
state
.
putInfo
(
"size"
,
uploadResult
.
get
(
"size"
).
toString
());
// ---自行处理---
state
.
putInfo
(
"title"
,
uploadResult
.
get
(
"title"
).
toString
());
return
state
;
state
.
putInfo
(
"url"
,
uploadResult
.
get
(
"url"
).
toString
());
}
// 把上传的文件信息记入数据库
}
catch
(
IOException
e
)
{
return
state
;
}
}
return
new
BaseState
(
false
,
AppInfo
.
IO_ERROR
);
return
new
BaseState
(
false
,
AppInfo
.
IO_ERROR
);
}
}
@Override
@Override
public
State
saveBinaryFile
(
byte
[]
data
,
String
fileName
)
{
public
State
saveBinaryFile
(
byte
[]
data
,
String
fileName
)
{
State
state
=
null
;
State
state
;
Map
<
String
,
Object
>
uploadResult
=
FastDFSUtils
.
uploadFile
(
data
,
fileName
);
ByteArrayInputStream
baos
=
new
ByteArrayInputStream
(
data
);
if
((
Boolean
)
uploadResult
.
get
(
"status"
))
{
Map
<
String
,
Object
>
uploadResult
=
FastDFSUtils
.
uploadImage
(
baos
,
0L
,
fileName
);
state
=
new
BaseState
(
true
);
if
((
Boolean
)
uploadResult
.
get
(
"status"
))
{
state
.
putInfo
(
"size"
,
uploadResult
.
get
(
"length"
).
toString
());
state
=
new
BaseState
(
true
);
state
.
putInfo
(
"title"
,
uploadResult
.
get
(
"fileName"
).
toString
());
state
.
putInfo
(
"size"
,
uploadResult
.
get
(
"size"
).
toString
());
// state.putInfo("groupName",
state
.
putInfo
(
"title"
,
uploadResult
.
get
(
"title"
).
toString
());
// uploadResult.get("groupName").toString());
state
.
putInfo
(
"url"
,
uploadResult
.
get
(
"url"
).
toString
());
// state.putInfo("storageFileName",
// 把上传的文件信息记入数据库
// uploadResult.get("storageFileName").toString());
return
state
;
state
.
putInfo
(
"url"
,
dfsFileAccessBasePath
+
"/"
+
uploadResult
.
get
(
"link"
).
toString
());
}
// 把上传的文件信息记入数据库
return
new
BaseState
(
false
,
AppInfo
.
IO_ERROR
);
// ---自行处理---
}
return
state
;
}
@Override
public
State
listFile
(
String
[]
allowFiles
,
int
start
,
int
pageSize
)
{
return
new
BaseState
(
false
,
AppInfo
.
IO_ERROR
);
// 把计入数据库中的文件信息读取出来,返回即可
}
// 下面的代码,仅作示例
@Override
State
state
=
new
MultiState
(
true
);
public
State
listFile
(
String
[]
allowFiles
,
int
start
,
int
pageSize
)
{
state
.
putInfo
(
"start"
,
start
);
// 把计入数据库中的文件信息读取出来,返回即可
state
.
putInfo
(
"total"
,
0
);
return
state
;
// 下面的代码,仅作示例
}
State
state
=
new
MultiState
(
true
);
state
.
putInfo
(
"start"
,
start
);
state
.
putInfo
(
"total"
,
0
);
return
state
;
}
}
}
src/main/java/cn/wisenergy/chnmuseum/party/web/controller/AssetController.java
View file @
2a329dd3
...
@@ -80,7 +80,7 @@ public class AssetController extends BaseController {
...
@@ -80,7 +80,7 @@ public class AssetController extends BaseController {
for
(
MultipartFile
file
:
files
)
{
for
(
MultipartFile
file
:
files
)
{
// 原始文件名
// 原始文件名
String
originalFilename
=
file
.
getOriginalFilename
();
String
originalFilename
=
file
.
getOriginalFilename
();
String
url
=
FastDFSUtils
.
upload
InputStream
(
file
.
getInputStream
(),
originalFilename
,
file
.
getSize
()
);
String
url
=
FastDFSUtils
.
upload
File
(
file
.
getInputStream
(),
file
.
getSize
(),
originalFilename
);
filesMetadata
.
add
(
AssetVo
.
builder
().
fileName
(
originalFilename
).
fileExt
(
FilenameUtils
.
getExtension
(
originalFilename
))
filesMetadata
.
add
(
AssetVo
.
builder
().
fileName
(
originalFilename
).
fileExt
(
FilenameUtils
.
getExtension
(
originalFilename
))
.
fileSize
(
file
.
getSize
()).
fileUrl
(
url
).
build
());
.
fileSize
(
file
.
getSize
()).
fileUrl
(
url
).
build
());
}
}
...
@@ -106,7 +106,7 @@ public class AssetController extends BaseController {
...
@@ -106,7 +106,7 @@ public class AssetController extends BaseController {
for
(
MultipartFile
file
:
files
)
{
for
(
MultipartFile
file
:
files
)
{
// 上传简单文件名
// 上传简单文件名
String
originalFilename
=
file
.
getOriginalFilename
();
String
originalFilename
=
file
.
getOriginalFilename
();
String
url
=
FastDFSUtils
.
upload
InputStream
(
file
.
getInputStream
(),
originalFilename
,
file
.
getSize
()
);
String
url
=
FastDFSUtils
.
upload
File
(
file
.
getInputStream
(),
file
.
getSize
(),
originalFilename
);
filesMetadata
.
put
(
originalFilename
.
trim
(),
url
);
filesMetadata
.
put
(
originalFilename
.
trim
(),
url
);
}
}
asset
.
setAuditStatus
(
AuditStatusEnum
.
TBC
.
name
());
asset
.
setAuditStatus
(
AuditStatusEnum
.
TBC
.
name
());
...
...
src/main/java/cn/wisenergy/chnmuseum/party/web/controller/PicUploadController.java
View file @
2a329dd3
...
@@ -4,7 +4,6 @@ import cn.wisenergy.chnmuseum.party.common.dfs.FastDFSUtils;
...
@@ -4,7 +4,6 @@ import cn.wisenergy.chnmuseum.party.common.dfs.FastDFSUtils;
import
cn.wisenergy.chnmuseum.party.common.vo.PicUploadResult
;
import
cn.wisenergy.chnmuseum.party.common.vo.PicUploadResult
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -13,8 +12,6 @@ import org.springframework.web.bind.annotation.RequestParam;
...
@@ -13,8 +12,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
/**
/**
* 图片上传
* 图片上传
*/
*/
...
@@ -23,8 +20,6 @@ import javax.servlet.http.HttpServletResponse;
...
@@ -23,8 +20,6 @@ import javax.servlet.http.HttpServletResponse;
public
class
PicUploadController
{
public
class
PicUploadController
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
PicUploadController
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
PicUploadController
.
class
);
@Value
(
"${IMAGE_BASE_URL}"
)
private
String
IMAGE_BASE_URL
;
// 允许上传的格式
// 允许上传的格式
private
static
final
String
[]
IMAGE_TYPE
=
new
String
[]{
".bmp"
,
".jpg"
,
".jpeg"
,
".png"
};
private
static
final
String
[]
IMAGE_TYPE
=
new
String
[]{
".bmp"
,
".jpg"
,
".jpeg"
,
".png"
};
...
@@ -80,23 +75,13 @@ public class PicUploadController {
...
@@ -80,23 +75,13 @@ public class PicUploadController {
// }
// }
@RequestMapping
(
value
=
"/upload"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/upload"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
PicUploadResult
>
uploadFile
(
@RequestParam
(
value
=
"cover"
)
MultipartFile
uploadFile
,
HttpServletResponse
response
)
throws
Exception
{
public
ResponseEntity
<
PicUploadResult
>
uploadFile
(
@RequestParam
(
value
=
"cover"
)
MultipartFile
uploadFile
)
throws
Exception
{
// 封装Result对象,并且将文件的byte数组放置到result对象中
PicUploadResult
fileUploadResult
=
new
PicUploadResult
();
PicUploadResult
fileUploadResult
=
new
PicUploadResult
();
if
(
uploadFile
.
getSize
()
/
(
1024
*
1024
)
>
1024
)
{
String
filePath
=
FastDFSUtils
.
uploadFile
(
uploadFile
.
getInputStream
(),
uploadFile
.
getSize
(),
uploadFile
.
getOriginalFilename
());
//50兆
log
.
error
(
"附件大小超过50兆!请重新上传 "
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
null
);
}
;
// 文件新路径
String
filePath
=
FastDFSUtils
.
uploadPic
(
uploadFile
.
getBytes
(),
uploadFile
.
getOriginalFilename
(),
uploadFile
.
getSize
());
if
(
log
.
isDebugEnabled
())
{
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"Pic file upload .[{}] to [{}] ."
,
uploadFile
.
getOriginalFilename
(),
filePath
);
log
.
debug
(
"Pic file upload .[{}] to [{}] ."
,
uploadFile
.
getOriginalFilename
(),
filePath
);
}
}
String
picUrl
=
IMAGE_BASE_URL
+
filePath
;
fileUploadResult
.
setUrl
(
filePath
);
fileUploadResult
.
setUrl
(
picUrl
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
fileUploadResult
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
fileUploadResult
);
}
}
...
...
src/main/java/com/baidu/ueditor/define/BaseState.java
View file @
2a329dd3
...
@@ -31,7 +31,8 @@ public class BaseState implements State {
...
@@ -31,7 +31,8 @@ public class BaseState implements State {
this
.
info
=
AppInfo
.
getStateInfo
(
infoCode
);
this
.
info
=
AppInfo
.
getStateInfo
(
infoCode
);
}
}
public
boolean
isSuccess
()
{
@Override
public
boolean
isSuccess
()
{
return
this
.
state
;
return
this
.
state
;
}
}
...
...
src/main/java/com/baidu/ueditor/extend/UEImageHunter.java
View file @
2a329dd3
package
com
.
baidu
.
ueditor
.
extend
;
package
com
.
baidu
.
ueditor
.
extend
;
import
com.baidu.ueditor.define.*
;
import
org.json.JSONObject
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -9,14 +12,6 @@ import java.util.Arrays;
...
@@ -9,14 +12,6 @@ import java.util.Arrays;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
org.json.JSONObject
;
import
com.baidu.ueditor.define.AppInfo
;
import
com.baidu.ueditor.define.BaseState
;
import
com.baidu.ueditor.define.MIMEType
;
import
com.baidu.ueditor.define.MultiState
;
import
com.baidu.ueditor.define.State
;
/**
/**
* 图片抓取器
* 图片抓取器
*
*
...
@@ -67,9 +62,11 @@ public class UEImageHunter {
...
@@ -67,9 +62,11 @@ public class UEImageHunter {
}
}
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setInstanceFollowRedirects
(
true
);
connection
.
setInstanceFollowRedirects
(
true
);
connection
.
setUseCaches
(
true
);
connection
.
setUseCaches
(
true
);
connection
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/5.0 (Windows 7; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36 YNoteCef/5.8.0.1 (Windows)"
);
connection
.
setRequestProperty
(
"Accept-Encoding"
,
"gzip,deflate,identity"
);
//connection.setRequestProperty("Range", "bytes=0-1");
if
(!
validContentState
(
connection
.
getResponseCode
()))
{
if
(!
validContentState
(
connection
.
getResponseCode
()))
{
return
new
BaseState
(
false
,
AppInfo
.
CONNECTION_ERROR
);
return
new
BaseState
(
false
,
AppInfo
.
CONNECTION_ERROR
);
...
@@ -89,8 +86,9 @@ public class UEImageHunter {
...
@@ -89,8 +86,9 @@ public class UEImageHunter {
urlStr
=
urlStr
.
substring
(
0
,
urlStr
.
indexOf
(
"?"
));
urlStr
=
urlStr
.
substring
(
0
,
urlStr
.
indexOf
(
"?"
));
}
}
String
fileName
=
urlStr
.
substring
(
urlStr
.
lastIndexOf
(
"/"
)
+
1
);
String
fileName
=
urlStr
.
substring
(
urlStr
.
lastIndexOf
(
"/"
)
+
1
);
long
contentLengthLong
=
connection
.
getContentLengthLong
();
State
state
=
this
.
ueditorService
.
saveBinaryFile
(
getBytes
(
connection
.
getInputStream
())
,
fileName
);
State
state
=
this
.
ueditorService
.
saveBinaryFile
(
connection
.
getInputStream
(),
contentLengthLong
,
fileName
);
if
(
state
.
isSuccess
())
{
if
(
state
.
isSuccess
())
{
JSONObject
jsonObj
=
new
JSONObject
(
state
.
toJSONString
());
JSONObject
jsonObj
=
new
JSONObject
(
state
.
toJSONString
());
...
...
src/main/java/com/baidu/ueditor/extend/UeditorService.java
View file @
2a329dd3
package
com
.
baidu
.
ueditor
.
extend
;
package
com
.
baidu
.
ueditor
.
extend
;
import
javax.servlet.http.HttpServletRequest
;
import
com.baidu.ueditor.define.State
;
import
com.baidu.ueditor.define.State
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.InputStream
;
public
interface
UeditorService
{
public
interface
UeditorService
{
/**
/**
...
@@ -25,6 +26,8 @@ public interface UeditorService {
...
@@ -25,6 +26,8 @@ public interface UeditorService {
*/
*/
public
State
saveFileByInputStream
(
MultipartFile
multipartFile
,
long
maxSize
);
public
State
saveFileByInputStream
(
MultipartFile
multipartFile
,
long
maxSize
);
public
State
saveBinaryFile
(
InputStream
inputStream
,
long
fileSize
,
String
fileName
);
/**
/**
* 存储文件
* 存储文件
*
*
...
...
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