zoukankan      html  css  js  c++  java
  • FastDfs上传图片

    1.1. 上传步骤

    1、加载配置文件,配置文件中的内容就是tracker服务的地址。

    配置文件内容:tracker_server=192.168.25.133:22122

    2、创建一个TrackerClient对象。直接new一个。

    3、使用TrackerClient对象创建连接,获得一个TrackerServer对象。

    4、创建一个StorageServer的引用,值为null

    5、创建一个StorageClient对象,需要两个参数TrackerServer对象、StorageServer的引用

    6、使用StorageClient对象上传图片。

    7、返回数组。包含组名和图片的路径。

    代码

    public class FastDFSTest {
    
    	@Test
    	public void testFileUpload() throws Exception {
    		// 1、加载配置文件,配置文件中的内容就是tracker服务的地址。
    		ClientGlobal.init("D:/workspaces-itcast/e3-manager-web/src/main/resources/resource/client.conf");
    		// 2、创建一个TrackerClient对象。直接new一个。
    		TrackerClient trackerClient = new TrackerClient();
    		// 3、使用TrackerClient对象创建连接,获得一个TrackerServer对象。
    		TrackerServer trackerServer = trackerClient.getConnection();
    		// 4、创建一个StorageServer的引用,值为null
    		StorageServer storageServer = null;
    		// 5、创建一个StorageClient对象,需要两个参数TrackerServer对象、StorageServer的引用
    		StorageClient storageClient = new StorageClient(trackerServer, storageServer);
    		// 6、使用StorageClient对象上传图片。
    		//扩展名不带“.”
    		String[] strings = storageClient.upload_file("D:/Documents/Pictures/images/200811281555127886.jpg", "jpg", null);
    		// 7、返回数组。包含组名和图片的路径。
    		for (String string : strings) {
    			System.out.println(string);
    		}
    	}
    }
    

    使用工具类上传

    @Test
    	public void testFastDfsClient() throws Exception {
    		FastDFSClient fastDFSClient = new FastDFSClient("D:/workspaces-itcast/e3-manager-web/src/main/resources/resource/client.conf");
    		String file = fastDFSClient.uploadFile("D:/Documents/Pictures/images/2f2eb938943d.jpg");
    		System.out.println(file);
    	}
    
  • 相关阅读:
    RabbitMQ~广播消息
    大数据~说说Hadoop
    大数据~说说ZooKeeper
    RabbitMQ~消费者实时与消息服务器保持通话
    c/c++测试程序运行时间
    7kb的javascript日期操作类库(XDate)
    提前防止Non-PIE错误,检测app是否包含PIE标志
    paip.数据库发邮件通知配置
    CADisplayLink 及定时器的使用
    HDU3415:Max Sum of Max-K-sub-sequence(单调队列)
  • 原文地址:https://www.cnblogs.com/daleyzou/p/8988892.html
Copyright © 2011-2022 走看看