FastDFS学习笔记 -- day03 上传图片测试
2017-06-13 10:12
417 查看
一、通过fdfs_test程序测试
1、fdfs_test说明:
FastDFS安装成功后可通过【fdfs_test】命令测试上传、下载等操作。2、进入/etc/fdfs/目录,拷贝一份client.conf文件
[root@localhost fdfs]# cp client.conf.sample client.conf
3、修改client.conf配置文件
base_path=/usr/local/fastdfs/client tracker_server=192.168.200.132:22122
注意:需要创建 /usr/local/fastdfs/client目录
[root@localhost fdfs]# mkdir /usr/local/fastdfs/client -p
4、使用fdfs_test命令上传图片
上传命令:/usr/bin/fdfs_test /etc/fdfs/client.conf upload 要上传的文件比如将/home下的图片1.png上传到FastDFS中:
[root@localhost fdfs]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/1.png
5、说明:
文件的下载访问路径:http://192.168.200.132/group1/M00/00/00/wKjIhFlCLMKACqmFAABWJUYHh50196_big.png对应storage服务器上的磁盘路径:/home/fastdfs/fdfs_storage/data/00/00/wKjIhFlCLMKACqmFAABWJUYHh50196_big.png
由于现在还没有整合Nginx,因此无法使用http下载
二、通过 java Client API 进行测试
1、创建java工程添,加以下jar包
如果是Maven工程,则需要通过pom文件添加jar包。不过该jar包,在中央仓库是没有的,需要将该jar包,安装到本地仓库或者私服。
2、编写测试代码
package fdfs_test;import java.net.URLDecoder;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.StorageServer;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.junit.Test;
public class TestClient {
private String file_ext_name = ".jpg";
private String local_filename = "G://temp//1.jpg";
@Test
public void test() throws Exception {
// 获取fdfs_client配置文件路径
String confPath = this.getClass().getResource("/fdfs/fdfs_client.conf").getPath();
// 如果路径中有中文,需要处理中文乱码问题
confPath = URLDecoder.decode(confPath, "utf-8");
// 加载fdfs_client配置文件
ClientGlobal.init(confPath);
// 创建TrackerClient
TrackerClient trackerClient = new TrackerClient();
// 创建TrackerServer
TrackerServer trackerServer = trackerClient.getConnection();
// 创建storageServer
StorageServer storageServer = null;
// 创建StorageClient1,客户端文件上传时,可以指定上传的服务期地址,也可以有trackerServer调度
StorageClient1 client1 = new StorageClient1(trackerServer, storageServer);
// 调用StorageClient1的api方法完成文件的上传操作
String upload_file1 = client1.upload_file1(local_filename, file_ext_name, null);
// 输出上传文件的file_id
System.out.println(upload_file1);
}
}
3、修改 fdfs_client.conf 文件,指定 tracker_server 的地址
相关文章推荐
- FastDFS学习笔记 -- day05 上传图片
- 【学习笔记⑥】ssh中利用struts实现图片的上传功能
- xhEditor在线编辑器学习笔记(1)---用Struts2+ajax实现图片上传
- FastDfs 学习进阶之环境安装及上传文件测试
- CAFFE学习笔记(二):训练和测试自己的图片
- 深度学习框架Caffe学习笔记(6)-测试自己的手写数字图片
- [学习笔记]jsp+javaBean 实现图片的上传
- 上传图片---SpringMVC学习笔记(十一)
- springmvc学习笔记(17)-上传图片
- (转) 淘淘商城系列——使用FastDFS-Client客户端进行上传图片的测试
- ant学习笔记(五)基于单元测试的j2se项目,包括编译、测试、打包、生成报告、上传ftp
- ExtJS4学习笔记四--图片上传
- ExtJS4学习笔记四--图片上传
- springMVC学习笔记--上传图片、JSON转对象、校验、全局异常、拦截器
- springMVC学习笔记---day04-上传图片、JSON转对象、校验、全局异常、拦截器、静态资源
- IIS图片上传大小限制的修改(学习笔记)
- JFinal学习笔记(四) 实现简单的图片上传
- 淘淘商城系列——使用FastDFS-Client客户端进行上传图片的测试
- iOS学习笔记--图片上传
- 学习笔记13 独立出discuz 论坛中的图片上传