Maven_Fastdfs 实例

Linux_FastDFS 安装笔记
Linux_FastDFS 集群安装笔记

这里写图片描述

org.csource.common和org.csource.fastdfs两个包来自于fastdfs-client-java

fdfs_client.conf

connect_timeout = 2
network_timeout = 30
charset = UTF-8
http.tracker_http_port = 8080
http.anti_steal_token = no
http.secret_key = FastDFS1234567890

tracker_server = 192.168.216.140:22122

FastdfsTest.java

package com.demo.fastdfs.test;

import java.io.IOException;

import org.csource.common.MyException;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class FastdfsTest {
    private static final String upload_file = "D:\\tortoise.jpg";
    private StorageClient1 client;
    private TrackerServer trackerServer;

    @Before
    public void init() throws IOException, MyException {
        ClientGlobal.init("fdfs_client.conf");

        trackerServer = new TrackerClient().getConnection();
        client = new StorageClient1(trackerServer, null);
    }

    @Test
    public void fdfs() throws IOException, MyException {

        NameValuePair[] metaList = new NameValuePair[1];
        metaList[0] = new NameValuePair("fileName", upload_file);

        // 上传文件
        String fileId = client.upload_file1(upload_file, null, metaList);
        System.out.println("upload success. file id is: " + fileId);

        // 下载文件
        byte[] result = client.download_file1(fileId);
        System.out.println("download result is: " + result.length);

        // 删除文件
        int code = client.delete_file1(fileId);
        System.out.println("0 for success, none zero for fail (error code): " + code);

        closeFastdfs();
    }

    @After
    public void closeFastdfs() throws IOException {
        if (trackerServer != null) {
            trackerServer.close();
        }

    }

}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo</groupId>
    <artifactId>maven-fastdfs</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

maven-fastfds 实例源码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值