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);
    	}
    
  • 相关阅读:
    Redis 2种持久化模式的缺陷
    我看过得最易懂的一段AOP的解释
    mysql-高性能索引策略
    几款效率神器助你走上人生巅峰
    shell脚本报错:"[: =: unary operator expected"
    CentOS7中使用iptables
    php foreach用法和实例
    shell 学习四十五天---xargs
    chain issues incorrect order,EXtra certs,Contains anchor
    Ubuntu 能ping通DNS 地址 无法解析域名
  • 原文地址:https://www.cnblogs.com/daleyzou/p/8988892.html
Copyright © 2011-2022 走看看