Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mikite
spring-boot-examples
提交
fcbe7263
S
spring-boot-examples
项目概览
Mikite
/
spring-boot-examples
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-boot-examples
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fcbe7263
编写于
1月 13, 2018
作者:
微笑很纯洁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
m
上级
e73f99b8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
63 addition
and
36 deletion
+63
-36
spring-boot-fastDFS/src/main/java/com/neo/config/Configurations.java
...-fastDFS/src/main/java/com/neo/config/Configurations.java
+0
-19
spring-boot-fastDFS/src/main/java/com/neo/controller/UploadController.java
...FS/src/main/java/com/neo/controller/UploadController.java
+4
-9
spring-boot-fastDFS/src/main/java/com/neo/fastdfs/FastDFSClient.java
...-fastDFS/src/main/java/com/neo/fastdfs/FastDFSClient.java
+6
-5
spring-boot-fastDFS/src/main/resources/application.properties
...ng-boot-fastDFS/src/main/resources/application.properties
+0
-1
spring-boot-fastDFS/src/main/resources/fdfs_client.conf
spring-boot-fastDFS/src/main/resources/fdfs_client.conf
+2
-2
spring-boot-file-upload/src/main/resources/templates/from_file.html
...t-file-upload/src/main/resources/templates/from_file.html
+51
-0
未找到文件。
spring-boot-fastDFS/src/main/java/com/neo/config/Configurations.java
已删除
100644 → 0
浏览文件 @
e73f99b8
package
com.neo.config
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
@Component
public
class
Configurations
{
@Value
(
"${fastdfs.base.url}"
)
private
String
fdfsUrl
;
public
String
getFdfsUrl
()
{
return
fdfsUrl
;
}
public
void
setFdfsUrl
(
String
fdfsUrl
)
{
this
.
fdfsUrl
=
fdfsUrl
;
}
}
\ No newline at end of file
spring-boot-fastDFS/src/main/java/com/neo/controller/UploadController.java
浏览文件 @
fcbe7263
package
com.neo.controller
;
import
com.neo.config.Configurations
;
import
com.neo.fastdfs.FastDFSClient
;
import
com.neo.fastdfs.FastDFSFile
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -19,8 +17,6 @@ import java.io.InputStream;
@Controller
public
class
UploadController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
UploadController
.
class
);
@Autowired
private
Configurations
configuration
;
@GetMapping
(
"/"
)
public
String
index
()
{
...
...
@@ -34,7 +30,6 @@ public class UploadController {
redirectAttributes
.
addFlashAttribute
(
"message"
,
"Please select a file to upload"
);
return
"redirect:uploadStatus"
;
}
try
{
// Get the file and save it somewhere
String
path
=
saveFile
(
file
);
...
...
@@ -73,13 +68,13 @@ public class UploadController {
FastDFSFile
file
=
new
FastDFSFile
(
fileName
,
file_buff
,
ext
);
try
{
fileAbsolutePath
=
FastDFSClient
.
upload
(
file
);
//upload to fastdfs
}
catch
(
Exception
e
1
)
{
e1
.
printStackTrace
(
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"upload file Exception!"
,
e
);
}
if
(
fileAbsolutePath
==
null
)
{
System
.
out
.
println
(
"upload file failed,please upload again!"
);
logger
.
error
(
"upload file failed,please upload again!"
);
}
String
path
=
configuration
.
getFdfs
Url
()+
fileAbsolutePath
[
0
]+
"/"
+
fileAbsolutePath
[
1
];
String
path
=
FastDFSClient
.
getTracker
Url
()+
fileAbsolutePath
[
0
]+
"/"
+
fileAbsolutePath
[
1
];
return
path
;
}
}
\ No newline at end of file
spring-boot-fastDFS/src/main/java/com/neo/fastdfs/FastDFSClient.java
浏览文件 @
fcbe7263
...
...
@@ -17,11 +17,8 @@ public class FastDFSClient {
static
{
try
{
Resource
resource
=
new
ClassPathResource
(
"fdfs_client.conf"
);
File
file
=
resource
.
getFile
();
String
configFile
=
file
.
getAbsolutePath
();
ClientGlobal
.
init
(
configFile
);
String
filePath
=
new
ClassPathResource
(
"fdfs_client.conf"
).
getFile
().
getAbsolutePath
();;
ClientGlobal
.
init
(
filePath
);
trackerClient
=
new
TrackerClient
();
trackerServer
=
trackerClient
.
getConnection
();
storageServer
=
trackerClient
.
getStoreStorage
(
trackerServer
);
...
...
@@ -100,4 +97,8 @@ public class FastDFSClient {
String
remoteFileName
)
throws
IOException
{
return
trackerClient
.
getFetchStorages
(
trackerServer
,
groupName
,
remoteFileName
);
}
public
static
String
getTrackerUrl
()
{
return
"http://"
+
trackerServer
.
getInetSocketAddress
().
getHostString
()+
":"
+
ClientGlobal
.
getG_tracker_http_port
()+
"/"
;
}
}
\ No newline at end of file
spring-boot-fastDFS/src/main/resources/application.properties
浏览文件 @
fcbe7263
...
...
@@ -3,4 +3,3 @@
spring.http.multipart.max-file-size
=
10MB
spring.http.multipart.max-request-size
=
10MB
fastdfs.base.url
=
http://192.168.53.85:8080/
\ No newline at end of file
spring-boot-fastDFS/src/main/resources/fdfs_client.conf
浏览文件 @
fcbe7263
connect_timeout
=
2
network_timeout
=
3
0
connect_timeout
=
60
network_timeout
=
6
0
charset
=
UTF
-
8
http
.
tracker_http_port
=
8080
http
.
anti_steal_token
=
no
...
...
spring-boot-file-upload/src/main/resources/templates/from_file.html
0 → 100644
浏览文件 @
fcbe7263
<form
id=
'myupload'
action=
'http://localhost:8080/uploadSign'
method=
'post'
enctype=
'multipart/form-data'
>
<div
class=
"demo"
>
<div
class=
"btn"
>
<span>
添加附件
</span>
<input
id=
"fileupload"
type=
"file"
name=
"file1"
></div>
<div
class=
"progress"
>
<span
class=
"bar"
></span>
<span
class=
"percent"
>
0%
</span></div>
<!-- 显示已上传的文件名 -->
<div
class=
"files"
></div>
<!-- 显示已上传的图片-->
<div
class=
"showimg"
></div>
</div>
<input
type=
"submit"
onclick=
"gosubmit2()"
/></form>
<script
src=
"https://cdn.bootcss.com/jquery/1.6.4/jquery.js"
></script>
<script
type=
"text/javascript"
src=
"https://cdn.bootcss.com/jquery.form/4.1.0/jquery.form.min.js"
></script>
<script
type=
"text/javascript"
>
var
bar
=
$
(
'
.bar
'
);
//进度条
var
percent
=
$
(
'
.percent
'
);
//获取上传百分比
var
showimg
=
$
(
'
.showimg
'
);
//显示图片的div
var
progress
=
$
(
'
.progress
'
);
//显示进度的div
var
files
=
$
(
'
.files
'
);
//文件上传控件的input元素
var
btn
=
$
(
'
.btn span
'
);
//按钮文本
function
gosubmit2
()
{
$
(
"
#myupload
"
).
ajaxSubmit
({
dataType
:
'
json
'
,
//返回数据类型
beforeSend
:
function
()
{
showimg
.
empty
();
progress
.
show
();
var
percentVal
=
'
0%
'
;
bar
.
width
(
percentVal
);
percent
.
html
(
percentVal
);
btn
.
html
(
'
上传中..
'
);
},
//更新进度条事件处理代码
uploadProgress
:
function
(
event
,
position
,
total
,
percentComplete
)
{
var
percentVal
=
percentComplete
+
'
%
'
;
bar
.
width
(
percentVal
);
percent
.
html
(
percentVal
);
},
success
:
function
(
data
)
{
//图片上传成功时
//获取服务器端返回的文件数据
alert
(
data
.
name
+
"
,
"
+
data
.
pic
+
"
,
"
+
data
.
size
);
},
error
:
function
(
xhr
)
{
btn
.
html
(
上传失败
);
bar
.
width
(
'
0
'
);
files
.
html
(
xhr
.
responseText
);
}
});
}
</script>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录