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

Conversation

jerry-yuan
Copy link

您好,针对问题#117,您的回答中采用的DefaultAppendFileStorageClient(或者说是DefaultGenerateStorageClient)不存在空扩展名的兼容问题,但是更为简单且常用的DefaultFastFileStorageClient中却仍然存在过度检查空扩展名的问题,导致无法使用FastFileStorageClient接口上传带有空扩展名的文件.
这里我删掉了那个参数检查,针对这一问题我在FastFileStorageClientTest中增加了相应测试,在我本地此测试可以通过并输出正确的FastDFS文件索引:

2020-06-30 11:36:38,815 [main] INFO  com.github.tobato.fastdfs.service.FastFileStorageClientTest - Started FastFileStorageClientTest in 5.079 seconds (JVM running for 7.594)
2020-06-30 11:36:38,867 [main] DEBUG com.github.tobato.fastdfs.service.FastFileStorageClientTest - ##上传具有null扩展名的文件..##
2020-06-30 11:36:38,880 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - 获取到Tracker连接地址localhost/127.0.0.1:22122
2020-06-30 11:36:38,888 [main] DEBUG com.github.tobato.fastdfs.domain.conn.DefaultConnection - connect to localhost/127.0.0.1:22122 soTimeout=1501 connectTimeout=1601
2020-06-30 11:36:38,906 [main] DEBUG com.github.tobato.fastdfs.domain.conn.DefaultConnection - check connection status of com.github.tobato.fastdfs.domain.conn.DefaultConnection@57adfab0 
2020-06-30 11:36:38,911 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - 对地址localhost/127.0.0.1:22122发出交易请求TrackerGetStoreStorageCommand
2020-06-30 11:36:38,952 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - return connect com.github.tobato.fastdfs.domain.conn.DefaultConnection@57adfab0
2020-06-30 11:36:38,965 [main] DEBUG com.github.tobato.fastdfs.domain.conn.DefaultConnection - connect to /169.254.43.205:23000 soTimeout=1501 connectTimeout=1601
2020-06-30 11:36:38,975 [main] DEBUG com.github.tobato.fastdfs.domain.conn.DefaultConnection - check connection status of com.github.tobato.fastdfs.domain.conn.DefaultConnection@476a736d 
2020-06-30 11:36:38,983 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - 对地址/169.254.43.205:23000发出交易请求StorageUploadFileCommand
2020-06-30 11:36:39,016 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - return connect com.github.tobato.fastdfs.domain.conn.DefaultConnection@476a736d
2020-06-30 11:36:39,016 [main] DEBUG com.github.tobato.fastdfs.service.FastFileStorageClientTest - 上传文件 result=StorePath [group=group1, path=M00/00/06/qf4rzV76s0eAM76WAAAAHmDODTU6808577]
2020-06-30 11:36:39,016 [main] DEBUG com.github.tobato.fastdfs.service.FastFileStorageClientTest - ##上传具有空字符串扩展名的文件..##
2020-06-30 11:36:39,016 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - 获取到Tracker连接地址localhost/127.0.0.1:22122
2020-06-30 11:36:39,017 [main] DEBUG com.github.tobato.fastdfs.domain.conn.DefaultConnection - check connection status of com.github.tobato.fastdfs.domain.conn.DefaultConnection@57adfab0 
2020-06-30 11:36:39,017 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - 对地址localhost/127.0.0.1:22122发出交易请求TrackerGetStoreStorageCommand
2020-06-30 11:36:39,017 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - return connect com.github.tobato.fastdfs.domain.conn.DefaultConnection@57adfab0
2020-06-30 11:36:39,018 [main] DEBUG com.github.tobato.fastdfs.domain.conn.DefaultConnection - check connection status of com.github.tobato.fastdfs.domain.conn.DefaultConnection@476a736d 
2020-06-30 11:36:39,018 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - 对地址/169.254.43.205:23000发出交易请求StorageUploadFileCommand
2020-06-30 11:36:39,031 [main] DEBUG com.github.tobato.fastdfs.domain.conn.FdfsConnectionManager - return connect com.github.tobato.fastdfs.domain.conn.DefaultConnection@476a736d
2020-06-30 11:36:39,031 [main] DEBUG com.github.tobato.fastdfs.service.FastFileStorageClientTest - 上传文件 result=StorePath [group=group1, path=M00/00/06/qf4rzV76s0eAPvx2AAAAHqpkC1U9838063]
2020-06-30 11:36:39,055 [Thread-2] WARN  org.springframework.jmx.export.annotation.AnnotationMBeanExporter - Could not unregister MBean [com.github.tobato.fastdfs.domain.conn:name=fdfsConnectionPool,type=FdfsConnectionPool] as said MBean is not registered (perhaps already unregistered by an external process)
2020-06-30 11:36:39,056 [Thread-2] DEBUG com.github.tobato.fastdfs.domain.conn.DefaultConnection - disconnect from Socket[addr=localhost/127.0.0.1,port=22122,localport=16562]
2020-06-30 11:36:39,061 [Thread-2] DEBUG com.github.tobato.fastdfs.domain.conn.DefaultConnection - disconnect from Socket[addr=/169.254.43.205,port=23000,localport=16564]

最后,感谢您在百忙中抽空Review我的代码.

增加针对DefaultFastFileStorageClient的空扩展名文件上传的测试
@jerry-yuan
Copy link
Author

补充一下,这个uploadFile函数位于DefaultGenerateStorageClient的实现:

/**
     * 上传不支持断点续传的文件
     */
    @Override
    public StorePath uploadFile(String groupName, InputStream inputStream, long fileSize, String fileExtName) {
        StorageNode client = trackerClient.getStoreStorage(groupName);
        StorageUploadFileCommand command = new StorageUploadFileCommand(client.getStoreIndex(), inputStream,
                fileExtName, fileSize, false);
        return fdfsConnectionManager.executeFdfsCmd(client.getInetSocketAddress(), command);
    }

没有对fileExtName进行校验,故如您在#117所介绍是支持空扩展名的,但是在DefaultFastFileStorageClient中您又实现了两个uploadFile方法:

/**
     * 上传文件
     */
    @Override
    public StorePath uploadFile(InputStream inputStream, long fileSize,
                                String fileExtName, Set<MetaData> metaDataSet) {
        FastFile fastFile;
        if (null == metaDataSet) {
            fastFile = new FastFile.Builder()
                    .withFile(inputStream, fileSize, fileExtName)
                    .build();
        } else {
            fastFile = new FastFile.Builder()
                    .withFile(inputStream, fileSize, fileExtName)
                    .withMetaData(metaDataSet)
                    .build();
        }
        return uploadFile(fastFile);
    }
/**
     * 上传文件
     * <pre>
     * 可通过fastFile对象配置
     * 1. 上传图像分组
     * 2. 上传元数据metaDataSet
     * <pre/>
     * @param fastFile
     * @return
     */
    @Override
    public StorePath uploadFile(FastFile fastFile) {
        Validate.notNull(fastFile.getInputStream(), "上传文件流不能为空");
        Validate.notBlank(fastFile.getFileExtName(), "文件扩展名不能为空");
        // 获取存储节点
        StorageNode client = getStorageNode(fastFile.getGroupName());
        // 上传文件
        return uploadFileAndMetaData(client, fastFile.getInputStream(),
                fastFile.getFileSize(), fastFile.getFileExtName(),
                fastFile.getMetaDataSet());
    }

第一个实现是调用第二个实现来完成实际流程的,而第二个中有检查文件扩展名为空的问题.
针对您提到的uploadImage必须指定扩展名的问题,这里没有更改上传图像/生成缩略图中针对扩展名检查的部分源码.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants