diff --git a/src/main/java/com/github/tobato/fastdfs/service/DefaultFastFileStorageClient.java b/src/main/java/com/github/tobato/fastdfs/service/DefaultFastFileStorageClient.java index 78168dc..5074283 100644 --- a/src/main/java/com/github/tobato/fastdfs/service/DefaultFastFileStorageClient.java +++ b/src/main/java/com/github/tobato/fastdfs/service/DefaultFastFileStorageClient.java @@ -105,7 +105,6 @@ public StorePath uploadImageAndCrtThumbImage(InputStream inputStream, @Override public StorePath uploadFile(FastFile fastFile) { Validate.notNull(fastFile.getInputStream(), "上传文件流不能为空"); - Validate.notBlank(fastFile.getFileExtName(), "文件扩展名不能为空"); // 获取存储节点 StorageNode client = getStorageNode(fastFile.getGroupName()); // 上传文件 diff --git a/src/test/java/com/github/tobato/fastdfs/service/FastFileStorageClientTest.java b/src/test/java/com/github/tobato/fastdfs/service/FastFileStorageClientTest.java index 97c9e04..b619abe 100644 --- a/src/test/java/com/github/tobato/fastdfs/service/FastFileStorageClientTest.java +++ b/src/test/java/com/github/tobato/fastdfs/service/FastFileStorageClientTest.java @@ -9,6 +9,7 @@ import com.github.tobato.fastdfs.domain.fdfs.StorePath; import com.github.tobato.fastdfs.domain.fdfs.ThumbImageConfig; import org.apache.commons.io.FilenameUtils; +import org.apache.logging.log4j.util.Strings; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -23,9 +24,11 @@ import java.io.InputStream; import java.util.HashSet; import java.util.Set; +import java.util.Collections; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; /** * FastFileStorageClient客户端 @@ -89,6 +92,33 @@ public void testUploadFileWithoutMetaData() { storageClient.deleteFile(path.getFullPath()); } + /** + * 测试上传文件的时候不提供后缀名称 + */ + @Test + public void testUploadWithoutExtName() { + // null扩展名的文件 + LOGGER.debug("##上传具有null扩展名的文件..##"); + RandomTextFile file = new RandomTextFile(); + file.setFileExtName(null); + assertNull(file.getFileExtName()); + + StorePath path = storageClient.uploadFile(file.getInputStream(), + file.getFileSize(), file.getFileExtName(), Collections.emptySet()); + assertNotNull(path); + LOGGER.debug("上传文件 result={}", path); + // 空字串扩展名文件 + LOGGER.debug("##上传具有空字符串扩展名的文件..##"); + file = new RandomTextFile(); + file.setFileExtName(Strings.EMPTY); + assertEquals(Strings.EMPTY, file.getFileExtName()); + + path = storageClient.uploadFile(file.getInputStream(), + file.getFileSize(), file.getFileExtName(), Collections.emptySet()); + assertNotNull(path); + LOGGER.debug("上传文件 result={}", path); + } + /** * 上传图片,并且生成缩略图 *