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);
    	}
    
  • 相关阅读:
    接口测试基础-ddt
    接口测试基础-json.loads-json数据格式转换成字典格式
    接口测试基础-拆包
    接口测试基础-导入第三方模块和删除第三方模块
    接口测试基础-正则表达式和参数化
    接口测试基础-Exece的操作-openpyxl模块
    matlab学习
    matlab学习笔记
    SSH框架配置及Maven使用
    运筹学框架图
  • 原文地址:https://www.cnblogs.com/daleyzou/p/8988892.html
Copyright © 2011-2022 走看看