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
42dafa18
Commit
42dafa18
authored
Mar 17, 2021
by
liqin
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
03e3d5ee
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
276 additions
and
279 deletions
+276
-279
FastDFSUtils.java
...cn/wisenergy/chnmuseum/party/common/dfs/FastDFSUtils.java
+137
-137
FastdfsUtil.java
.../cn/wisenergy/chnmuseum/party/common/dfs/FastdfsUtil.java
+139
-142
No files found.
src/main/java/cn/wisenergy/chnmuseum/party/common/dfs/FastDFSUtils.java
View file @
42dafa18
...
@@ -4,11 +4,12 @@ import org.apache.commons.io.FilenameUtils;
...
@@ -4,11 +4,12 @@ import org.apache.commons.io.FilenameUtils;
import
org.csource.common.MyException
;
import
org.csource.common.MyException
;
import
org.csource.common.NameValuePair
;
import
org.csource.common.NameValuePair
;
import
org.csource.fastdfs.*
;
import
org.csource.fastdfs.*
;
import
org.springframework.core.io.ClassPathResource
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.util.Properties
;
/**
/**
* 上传图片到FastDFS
* 上传图片到FastDFS
...
@@ -17,12 +18,11 @@ public class FastDFSUtils {
...
@@ -17,12 +18,11 @@ public class FastDFSUtils {
static
{
static
{
try
{
try
{
ClientGlobal
.
initByProperties
(
FastDFSUtils
.
class
.
getClassLoader
().
getResource
(
"fastdfs-client.properties"
).
getPath
());
Properties
props
=
new
Properties
();
}
catch
(
FileNotFoundException
e
)
{
final
InputStream
in
=
new
ClassPathResource
(
"fastdfs-client.properties"
).
getInputStream
();
e
.
printStackTrace
();
props
.
load
(
in
);
}
catch
(
IOException
e
)
{
ClientGlobal
.
initByProperties
(
props
);
e
.
printStackTrace
();
}
catch
(
IOException
|
MyException
e
)
{
}
catch
(
MyException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
...
...
src/main/java/cn/wisenergy/chnmuseum/party/common/dfs/FastdfsUtil.java
View file @
42dafa18
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
dfs
;
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
dfs
;
import
org.apache.commons.io.FilenameUtils
;
import
org.csource.common.NameValuePair
;
import
org.csource.fastdfs.ClientGlobal
;
import
org.csource.fastdfs.StorageClient
;
import
org.csource.fastdfs.TrackerClient
;
import
org.csource.fastdfs.TrackerServer
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.core.io.ClassPathResource
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Date
;
import
java.util.Properties
;
import
javax.imageio.ImageIO
;
import
org.apache.commons.io.FilenameUtils
;
import
org.csource.common.NameValuePair
;
import
org.csource.fastdfs.*
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
/**
* ueditor
* ueditor
...
@@ -24,10 +30,10 @@ public class FastdfsUtil {
...
@@ -24,10 +30,10 @@ public class FastdfsUtil {
private
static
boolean
isInit
=
false
;
private
static
boolean
isInit
=
false
;
private
static
void
init
()
throws
Exception
{
private
static
void
init
()
throws
Exception
{
String
classPath
=
new
File
(
FastdfsUtil
.
class
.
getResource
(
"/"
).
getFile
()).
getCanonicalPath
();
Properties
props
=
new
Properties
();
String
configFilePath
=
classPath
+
File
.
separator
+
"fastdfs-client.properties"
;
final
InputStream
in
=
new
ClassPathResource
(
"fastdfs-client.properties"
).
getInputStream
()
;
logger
.
info
(
"FastdfsUtils.init加载配置文件:"
+
configFilePath
);
props
.
load
(
in
);
ClientGlobal
.
initByProperties
(
configFilePath
);
ClientGlobal
.
initByProperties
(
props
);
}
}
private
static
TrackerClient
getTrackerClient
()
throws
Exception
{
private
static
TrackerClient
getTrackerClient
()
throws
Exception
{
...
@@ -35,9 +41,7 @@ public class FastdfsUtil {
...
@@ -35,9 +41,7 @@ public class FastdfsUtil {
init
();
init
();
isInit
=
true
;
isInit
=
true
;
}
}
return
new
TrackerClient
();
TrackerClient
trackerClient
=
new
TrackerClient
();
return
trackerClient
;
}
}
private
static
TrackerServer
getTrackerServer
()
throws
Exception
{
private
static
TrackerServer
getTrackerServer
()
throws
Exception
{
...
@@ -46,12 +50,7 @@ public class FastdfsUtil {
...
@@ -46,12 +50,7 @@ public class FastdfsUtil {
private
static
StorageClient
getStorageClient
()
throws
Exception
{
private
static
StorageClient
getStorageClient
()
throws
Exception
{
TrackerServer
trackerServer
=
getTrackerServer
();
TrackerServer
trackerServer
=
getTrackerServer
();
return
new
StorageClient
(
trackerServer
,
null
);
// StorageServer storageServer = null;
// StorageClient storageClient = new StorageClient(trackerServer,
// storageServer);
StorageClient
storageClient
=
new
StorageClient
(
trackerServer
,
null
);
return
storageClient
;
}
}
/**
/**
...
@@ -83,16 +82,14 @@ public class FastdfsUtil {
...
@@ -83,16 +82,14 @@ public class FastdfsUtil {
int
height
=
0
;
int
height
=
0
;
if
(
isImage
)
{
if
(
isImage
)
{
int
[]
imageInfo
=
getImageInfo
(
fileBuff
);
int
[]
imageInfo
=
getImageInfo
(
fileBuff
);
if
(
imageInfo
!=
null
)
{
width
=
imageInfo
[
0
];
width
=
imageInfo
[
0
];
height
=
imageInfo
[
1
];
height
=
imageInfo
[
1
];
}
}
}
NameValuePair
[]
metaList
=
new
NameValuePair
[]
{
new
NameValuePair
(
"fileName"
,
fileName
),
NameValuePair
[]
metaList
=
new
NameValuePair
[]{
new
NameValuePair
(
"fileName"
,
fileName
),
new
NameValuePair
(
"isImage"
,
isImage
+
""
),
new
NameValuePair
(
"mimeType"
,
mimeType
),
new
NameValuePair
(
"isImage"
,
isImage
+
""
),
new
NameValuePair
(
"mimeType"
,
mimeType
),
new
NameValuePair
(
"width"
,
width
+
""
),
new
NameValuePair
(
"height"
,
height
+
""
),
new
NameValuePair
(
"width"
,
width
+
""
),
new
NameValuePair
(
"height"
,
height
+
""
),
new
NameValuePair
(
"author"
,
"FastdfsUtils"
)
};
new
NameValuePair
(
"author"
,
"FastdfsUtils"
)
};
boolean
status
=
false
;
boolean
status
=
false
;
String
message
=
"文件上传失败!"
;
String
message
=
"文件上传失败!"
;
logger
.
info
(
"startTIme:"
+
(
new
Date
().
getMinutes
()));
logger
.
info
(
"startTIme:"
+
(
new
Date
().
getMinutes
()));
...
@@ -136,11 +133,11 @@ public class FastdfsUtil {
...
@@ -136,11 +133,11 @@ public class FastdfsUtil {
BufferedImage
image
=
ImageIO
.
read
(
in
);
// 将in作为输入流,读取图片存入image中,而这里in可以为ByteArrayInputStream();
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
)
{
logger
.
error
(
"FastdfsUtils.getImageInfo时发生异常:"
,
e
);
logger
.
error
(
"FastdfsUtils.getImageInfo时发生异常:"
,
e
);
}
}
return
new
int
[]
{
0
,
0
};
return
new
int
[]{
0
,
0
};
}
}
private
static
String
[]
storeFile
(
byte
[]
fileBuff
,
String
fileExtName
,
NameValuePair
[]
metaList
)
{
private
static
String
[]
storeFile
(
byte
[]
fileBuff
,
String
fileExtName
,
NameValuePair
[]
metaList
)
{
...
...
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