Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
C
chinafrica
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
chinafrica
Commits
f5d58b02
提交
f5d58b02
authored
3月 23, 2020
作者:
zgy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成图片上传接口
上级
7ccbf8f4
全部展开
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
134 行增加
和
0 行删除
+134
-0
uploadController.java
...in/java/com/platform/controller/api/uploadController.java
+24
-0
BASE64DecodedMultipartFile.java
.../java/com/platform/entity/BASE64DecodedMultipartFile.java
+110
-0
没有找到文件。
platform-admin/src/main/java/com/platform/controller/api/uploadController.java
浏览文件 @
f5d58b02
差异被折叠。
点击展开。
platform-admin/src/main/java/com/platform/entity/BASE64DecodedMultipartFile.java
0 → 100644
浏览文件 @
f5d58b02
package
com
.
platform
.
entity
;
import
cn.hutool.core.codec.Base64
;
import
org.springframework.web.multipart.MultipartFile
;
import
sun.misc.BASE64Decoder
;
import
java.io.*
;
/**
* @Auther: wudepeng
* @Date: 2020/03/22
* @Description:
*/
public
class
BASE64DecodedMultipartFile
implements
MultipartFile
{
private
final
byte
[]
imgContent
;
private
final
String
header
;
public
BASE64DecodedMultipartFile
(
byte
[]
imgContent
,
String
header
)
{
this
.
imgContent
=
imgContent
;
this
.
header
=
header
.
split
(
";"
)[
0
];
}
@Override
public
String
getName
()
{
return
System
.
currentTimeMillis
()
+
Math
.
random
()
+
"."
+
header
.
split
(
"/"
)[
1
];
}
@Override
public
String
getOriginalFilename
()
{
return
System
.
currentTimeMillis
()
+
(
int
)
Math
.
random
()
*
10000
+
"."
+
header
.
split
(
"/"
)[
1
];
}
@Override
public
String
getContentType
()
{
return
header
.
split
(
":"
)[
1
];
}
@Override
public
boolean
isEmpty
()
{
return
imgContent
==
null
||
imgContent
.
length
==
0
;
}
@Override
public
long
getSize
()
{
return
imgContent
.
length
;
}
@Override
public
byte
[]
getBytes
()
throws
IOException
{
return
imgContent
;
}
@Override
public
InputStream
getInputStream
()
throws
IOException
{
return
new
ByteArrayInputStream
(
imgContent
);
}
@Override
public
void
transferTo
(
File
dest
)
throws
IOException
,
IllegalStateException
{
new
FileOutputStream
(
dest
).
write
(
imgContent
);
}
public
static
MultipartFile
base64ToMultipart
(
String
base64
)
{
try
{
String
[]
baseStrs
=
base64
.
split
(
","
);
BASE64Decoder
decoder
=
new
BASE64Decoder
();
byte
[]
b
=
new
byte
[
0
];
b
=
decoder
.
decodeBuffer
(
baseStrs
[
1
]);
for
(
int
i
=
0
;
i
<
b
.
length
;
++
i
)
{
if
(
b
[
i
]
<
0
)
{
b
[
i
]
+=
256
;
}
}
return
new
BASE64DecodedMultipartFile
(
b
,
baseStrs
[
0
]);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
public
static
File
base64ToFile
(
String
base64
)
{
if
(
base64
==
null
||
""
.
equals
(
base64
))
{
return
null
;
}
byte
[]
buff
=
Base64
.
decode
(
base64
);
File
file
=
null
;
FileOutputStream
fout
=
null
;
try
{
file
=
File
.
createTempFile
(
"tmp"
,
null
);
fout
=
new
FileOutputStream
(
file
);
fout
.
write
(
buff
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
fout
!=
null
)
{
try
{
fout
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
file
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论