Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复DefaultFastFileStorageClient不兼容空扩展名的问题 #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
// 上传文件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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客户端
Expand Down Expand Up @@ -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.<MetaData>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.<MetaData>emptySet());
assertNotNull(path);
LOGGER.debug("上传文件 result={}", path);
}

/**
* 上传图片,并且生成缩略图
* <pre>
Expand Down