Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-fb
Overview
Overview
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
王衍超
cloud-fb
Commits
f5988d6d
Commit
f5988d6d
authored
Nov 10, 2021
by
高晓磊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除base64转文件类
parent
79257eae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
79 deletions
+0
-79
BASE64DecodedMultipartFile.java
...m/beecode/inz/common/util/BASE64DecodedMultipartFile.java
+0
-79
No files found.
backend/inz.common/src/main/java/com/beecode/inz/common/util/BASE64DecodedMultipartFile.java
deleted
100644 → 0
View file @
79257eae
package
com
.
beecode
.
inz
.
common
.
util
;
import
org.springframework.web.multipart.MultipartFile
;
import
sun.misc.BASE64Decoder
;
import
java.io.*
;
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
;
}
}
}
\ No newline at end of file
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