mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-03 12:18:01 +08:00
add uoload check
This commit is contained in:
parent
93df8333df
commit
103f352cf4
@ -10,6 +10,7 @@
|
||||
* 【extra 】 ArrayUtil增加map方法重载
|
||||
* 【crypto 】 AsymmetricAlgorithm增加RSA_ECB("RSA/ECB/NoPadding")(issue#1368@Github)
|
||||
* 【core 】 补充StrUtil.padXXX注释(issue#I2E1S7@Gitee)
|
||||
* 【core 】 修改上传文件检查逻辑
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 修复FileUtil.move以及PathUtil.copy等无法自动创建父目录的问题(issue#I2CKTI@Gitee)
|
||||
|
@ -840,7 +840,7 @@ public class FileUtil extends PathUtil {
|
||||
int exceptionsCount = 0;
|
||||
while (true) {
|
||||
try {
|
||||
File file = File.createTempFile(prefix, suffix, dir).getCanonicalFile();
|
||||
File file = File.createTempFile(prefix, suffix, mkdir(dir)).getCanonicalFile();
|
||||
if (isReCreat) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.delete();
|
||||
@ -978,6 +978,8 @@ public class FileUtil extends PathUtil {
|
||||
* @see PathUtil#move(Path, Path, boolean)
|
||||
*/
|
||||
public static void move(File src, File target, boolean isOverride) throws IORuntimeException {
|
||||
Assert.notNull(src, "Src file must be not null!");
|
||||
Assert.notNull(target, "target file must be not null!");
|
||||
move(src.toPath(), target.toPath(), isOverride);
|
||||
}
|
||||
|
||||
|
@ -71,10 +71,10 @@ public class MultipartFormData {
|
||||
if (fileName.length() > 0 && header.contentType.contains("application/x-macbinary")) {
|
||||
input.skipBytes(128);
|
||||
}
|
||||
UploadFile newFile = new UploadFile(header, setting);
|
||||
newFile.processStream(input);
|
||||
|
||||
final UploadFile newFile = new UploadFile(header, setting);
|
||||
if(newFile.processStream(input)){
|
||||
putFile(header.formFieldName, newFile);
|
||||
}
|
||||
} else {
|
||||
// 标准表单项
|
||||
putParameter(header.formFieldName, input.readString(charset));
|
||||
|
@ -9,6 +9,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
|
||||
/**
|
||||
* 上传的文件对象
|
||||
@ -86,12 +87,19 @@ public class UploadFile {
|
||||
destination = new File(destination, this.header.getFileName());
|
||||
}
|
||||
if (data != null) {
|
||||
// 内存中
|
||||
FileUtil.writeBytes(data, destination);
|
||||
data = null;
|
||||
} else {
|
||||
if (tempFile != null) {
|
||||
FileUtil.move(tempFile, destination, true);
|
||||
// 临时文件
|
||||
if(null == this.tempFile){
|
||||
throw new NullPointerException("Temp file is null !");
|
||||
}
|
||||
if(false == this.tempFile.exists()){
|
||||
throw new NoSuchFileException("Temp file: [" + this.tempFile.getAbsolutePath() + "] not exist!");
|
||||
}
|
||||
|
||||
FileUtil.move(tempFile, destination, true);
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
@ -51,10 +51,10 @@ public class UploadTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void uploadTest() {
|
||||
public void uploadTest2() {
|
||||
//客户端
|
||||
String url = "http://localhost:8888/file";
|
||||
Path file = Paths.get("D:\\testBigData_upload.xlsx");
|
||||
String url = "http://192.168.1.200:8888/meta/upload/img";
|
||||
Path file = Paths.get("D:\\test\\testBigData_upload.xlsx");
|
||||
Map<String, String> headers = new HashMap<>(16);
|
||||
headers.put("md5", "aaaaaaaa");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user