|
|
@ -1,18 +1,19 @@
|
|
|
|
package com.java3y.austin.web.utils;
|
|
|
|
package com.java3y.austin.web.utils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @author 3y
|
|
|
|
* @author 3y
|
|
|
|
* multipartFile 转成 File 对象
|
|
|
|
* multipartFile 转成 File 对象
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
public class SpringFileUtils {
|
|
|
|
public class SpringFileUtils {
|
|
|
|
private SpringFileUtils() {
|
|
|
|
private SpringFileUtils() {
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -26,23 +27,14 @@ public class SpringFileUtils {
|
|
|
|
public static File getFile(MultipartFile multipartFile) {
|
|
|
|
public static File getFile(MultipartFile multipartFile) {
|
|
|
|
String fileName = multipartFile.getOriginalFilename();
|
|
|
|
String fileName = multipartFile.getOriginalFilename();
|
|
|
|
File file = new File(fileName);
|
|
|
|
File file = new File(fileName);
|
|
|
|
OutputStream out = null;
|
|
|
|
try (OutputStream out = new FileOutputStream(file)){
|
|
|
|
try {
|
|
|
|
|
|
|
|
out = new FileOutputStream(file);
|
|
|
|
|
|
|
|
byte[] ss = multipartFile.getBytes();
|
|
|
|
byte[] ss = multipartFile.getBytes();
|
|
|
|
for (int i = 0; i < ss.length; i++) {
|
|
|
|
for (int i = 0; i < ss.length; i++) {
|
|
|
|
out.write(ss[i]);
|
|
|
|
out.write(ss[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
log.error("SpringFileUtils#getFile multipartFile is converted to File error:{}", e);
|
|
|
|
} finally {
|
|
|
|
return null;
|
|
|
|
if (Objects.nonNull(out)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|