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);
    	}
    
  • 相关阅读:
    stenciljs 学习四 组件装饰器
    stenciljs 学习三 组件生命周期
    stenciljs 学习二 pwa 简单应用开发
    stenciljs ionic 团队开发的方便web 组件框架
    stenciljs 学习一 web 组件开发
    使用npm init快速创建web 应用
    adnanh webhook 框架 hook rule
    adnanh webhook 框架 hook 定义
    adnanh webhook 框架request values 说明
    adnanh webhook 框架execute-command 以及参数传递处理
  • 原文地址:https://www.cnblogs.com/daleyzou/p/8988892.html
Copyright © 2011-2022 走看看