Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Walter.Wen
SpringBootFileUploadDownload
提交
ba1a60b9
S
SpringBootFileUploadDownload
项目概览
Walter.Wen
/
SpringBootFileUploadDownload
通知
5
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBootFileUploadDownload
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ba1a60b9
编写于
3月 20, 2020
作者:
W
wenguang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
头像上传功能实现
上级
ad1167cb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
2 deletion
+48
-2
src/main/java/com/we/controller/PhotographController.java
src/main/java/com/we/controller/PhotographController.java
+47
-0
src/main/resources/templates/photograph/photo.html
src/main/resources/templates/photograph/photo.html
+1
-2
未找到文件。
src/main/java/com/we/controller/PhotographController.java
浏览文件 @
ba1a60b9
...
...
@@ -3,6 +3,19 @@ package com.we.controller;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.multipart.MultipartFile
;
import
sun.misc.BASE64Decoder
;
import
sun.text.resources.FormatData
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.text.DateFormat
;
import
java.text.Format
;
import
java.util.Date
;
@Controller
@RequestMapping
(
"/photograph"
)
...
...
@@ -14,4 +27,38 @@ public class PhotographController {
return
prefix
+
"/photo"
;
}
/**
* 头像上传
* @param file
* @return
*/
@RequestMapping
(
"/photoUpload"
)
@ResponseBody
public
String
fileUpload
(
@RequestParam
(
"op"
)
String
op
,
@RequestParam
(
"base64url"
)
String
base64url
)
{
if
(!
"takePhoto"
.
equals
(
op
))
{
return
"false"
;
}
BASE64Decoder
decoder
=
new
BASE64Decoder
();
try
{
// Base64解码
byte
[]
b
=
decoder
.
decodeBuffer
(
base64url
);
for
(
int
i
=
0
;
i
<
b
.
length
;
++
i
)
{
if
(
b
[
i
]
<
0
)
{
// 调整异常数据
b
[
i
]
+=
256
;
}
}
String
imgFilePath
=
"D:\\datafile\\photo.jpg"
;
OutputStream
out
=
new
FileOutputStream
(
imgFilePath
);
out
.
write
(
b
);
out
.
flush
();
out
.
close
();
return
"true"
;
}
catch
(
Exception
e
)
{
return
"false"
;
}
}
}
src/main/resources/templates/photograph/photo.html
浏览文件 @
ba1a60b9
...
...
@@ -84,7 +84,6 @@
mediaStreamTrack
&&
mediaStreamTrack
.
stop
();
$
(
"
#video
"
).
hide
();
$
(
"
#showImg
"
).
show
();
}
//cropper图片裁剪
$
(
'
#tailoringImg
'
).
cropper
({
...
...
@@ -136,7 +135,7 @@
var
cas
=
$
(
'
#tailoringImg
'
).
cropper
(
'
getCroppedCanvas
'
);
//获取被裁剪后的canvas
var
base64url
=
cas
.
toDataURL
(
'
image/png
'
);
//转换为base64地址形式
base64url
=
base64url
.
replace
(
"
\r
"
,
""
)
$
.
post
(
"
../Info
"
,
{
op
:
"
takePhoto
"
,
base64url
:
base64url
},
function
(
data
)
{
$
.
post
(
"
/photograph/photoUpload
"
,
{
op
:
"
takePhoto
"
,
base64url
:
base64url
},
function
(
data
)
{
var
result
=
parseInt
(
$
.
trim
(
data
.
result
));
if
(
result
==-
1
){
$
.
messager
.
show
({
title
:
"
温馨提示
"
,
msg
:
"
输入的信息不完整,确认后重新提交。
"
,
timeout
:
3000
,
showType
:
'
slide
'
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录