亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java程序測(cè)試上傳Maven工程代碼示例解析

 更新時(shí)間:2020年08月19日 09:45:26   作者:emdzz  
這篇文章主要介紹了Java程序測(cè)試上傳Maven工程代碼示例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

創(chuàng)建普通Maven工程

導(dǎo)入所需依賴坐標(biāo):

<dependencies>
    <!-- https://mvnrepository.com/artifact/net.oschina.zcx7878/fastdfs-client-java -->
    <dependency>
      <groupId>net.oschina.zcx7878</groupId>
      <artifactId>fastdfs-client-java</artifactId>
      <version>1.27.0.0</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.2.8.RELEASE</version>
    </dependency>
  </dependencies>

在Resource目錄中編寫FastDFS配置文件【fdfs_client.conf】

connect_timeout=30
network_timeout=60
base_path=/home/fastdfs
#改為自己服務(wù)器的ip
tracker_server=服務(wù)器或者虛擬IP地址:22122
log_level=info
use_connection_pool = false
connection_pool_max_idle_time = 3600
load_fdfs_parameters_from_tracker=false
use_storage_id = false
storage_ids_filename = storage_ids.conf
http.tracker_server_port=80

編寫測(cè)試類:

@Test
  public void testSample() throws Exception{
    // 上傳的文件
    String filePath = "C:\\Users\\User-Dai\\Pictures\\Saved Pictures\\245099.jpg";

    // FastDFS上傳需要的配置文件
    String configurationFilePath = new ClassPathResource("fdfs_client.conf").getFile().getAbsolutePath();
    System.out.println(configurationFilePath);


    // 1、加載配置文件,配置文件中的內(nèi)容就是 tracker 服務(wù)的地址。
    ClientGlobal.init(configurationFilePath);

    // 2、創(chuàng)建一個(gè) TrackerClient 對(duì)象。直接 new 一個(gè)。
    TrackerClient trackerClient = new TrackerClient();

    // 3、使用 TrackerClient 對(duì)象創(chuàng)建連接,獲得一個(gè) TrackerServer 對(duì)象。
    TrackerServer trackerServer = trackerClient.getConnection();

    // 4、創(chuàng)建一個(gè) StorageServer 的引用,值為 null
    StorageServer storageServer = null;

    // 5、創(chuàng)建一個(gè) StorageClient 對(duì)象,需要兩個(gè)參數(shù) TrackerServer 對(duì)象、StorageServer 的引用
    StorageClient storageClient = new StorageClient(trackerServer, storageServer);
    // 6、使用 StorageClient 對(duì)象上傳圖片。
    //擴(kuò)展名不帶“.”
    String[] strings = storageClient.upload_file(filePath, "jpg", null);

    // 7、返回?cái)?shù)組。包含組名和圖片的路徑。
    for (String string : strings) {
      System.out.println(string);
    }
    System.out.println("上傳完成");
  }

測(cè)試結(jié)果:

C:\Users\User-Dai\IdeaProjects\FastDFS\target\classes\fdfs_client.conf
group1
M00/00/00/rBEAB180jHGAZ-ZDAAPzHYbtkp4809.jpg
上傳完成

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論