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:22122FastdfsTest.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 实例源码