爱萝莉真是太好了 爱萝莉真是太好了

努力让自己变得更优秀呀!

目录
fastdfs文件系统增加自定义路径(M00,M01,N02...)
/    

fastdfs文件系统增加自定义路径(M00,M01,N02...)

实现:自定义上传 M00/M01/M02 等路径

1.准备好 fdfs 服务,没有的话先搭建。点击这里

2.进入 storage 容器,修改配置文件/etc/fdfs/storage.conf(不同安装可能路径不一样)

1# path(disk or mount point) count, default value is 1(挂载点数量,默认值为1)
2store_path_count=2
3
4# store_path#, based 0, if store_path0 not exists, it's value is base_path(如果store_path0不存在,将使用base_path路径)
5# the paths must be exist (文件夹必须存在)
6store_path0=/var/fdfs
7store_path1=/var/fdfs/data2

这里修改 count 为 2 , 下边增加 store_path1=/var/fdfs/data2

3.然后呢?然后就结束了

4.使用 java-sdk 怎么上传指定路径

 1    @Value("${fastdfs.tracker_servers}")
 2    public void setTrackerServers(String tracker_servers){
 3        try {
 4        	ClientGlobal.initByTrackers(tracker_servers);
 5        	trackerClient = new TrackerClient();
 6            trackerServer = trackerClient.getConnection();
 7        	log.info("FastDFS.ClientGlobal.initByTrackers");
 8        } catch (Exception e) {
 9            log.error("FastDFS Client Init Fail!",e);
10        }
11    }
12   
13
14    protected static TrackerClient trackerClient;
15    protected static TrackerServer trackerServer;
16    protected static StorageServer storageServer;
17    protected static StorageClient storageClient;
18
19
20    //文件上传
21    public static String uploadFile(byte[] file_buff, String fileExtName) throws IOException, MyException {
22  
23    	storageServer = trackerClient.getStoreStorage(trackerServer);
24    	String storageIp = storageServer.getSocket().getInetAddress().getHostAddress();  
25    	Integer port = storageServer.getSocket().getPort();  
26        //这里的第三个参数就是指定路径下标的,0->M00->store_path0 , 1->M01->store_path1 ...
27    	storageServer = new StorageServer(storageIp, port, 1);
28 
29        StorageClient1 client = new StorageClient1(trackerServer, storageServer);
30        // 直接调用StorageClient对象方法上传文件即可。
31        String fileName = client.upload_file1(file_buff, fileExtName, null);
32        log.info("文件上传成功,路径为:{}" , fileName);
33        return fileName;
34    }
35

结果(到 M01 了)

1INFO 48996 --- [           main] c.Y.common.util.dfs.FastDFSClientUtil    : 文件上传成功,路径为:group1/M01/03/82/T489ul8IJ9OAHG8BAABmIZYby_8670.jpg

5.下次更新上传给指定 group 的文章..


标题:fastdfs文件系统增加自定义路径(M00,M01,N02...)
地址:https://www.1-love.cn/FastDFS-DIY-M00-M01-M02.html