为什么80%的码农都做不了架构师?>>>
1. 目的
本文档基于Java讲解fastDFS在接口调用的简单讲解。让您更快、更便捷的入门使用fastDFS-Client.jar。
2. 范围
Java、.net后端开发、使用http协议上传下载文件的语言
3. 概述
3.1 FastDFS安装教程:
地址:https://my.oschina.net/xwzj/blog/760862
3.2 接口源码
源码git:https://git.oschina.net/keeplearning996/springboot-fastdfs.git
jar直接下载链接:https://share.weiyun.com/5atHotG 密码:r6l1tj
启动相关参数:
java –jar fastDFS-Client.jar tracker地址 tracker端口
修改端口启动:
java -Dserver.port=8888 -jar fastDFS-Client.jar 192.168.1.157 22122
(ps:需要设置其他相关的参数可以自己下载源码修改或者联系作者)
Windows jar: java -Dserver.port=8888 -jar fastDFS-Client.jar 192.168.1.157 22122
Centos jar: java -Dserver.port=8888 -jar fastDFS-Client.jar 192.168.1.157 22122 &
(ps:centos必须有&让其后台执行,否则没有pid生成)
启动测试地址:http://host:port/fastdfs
4.接口说明
接口说明模板(ps:带*为必填项):
|
|
|
*url | http://host:port/demo/demo |
|
method | post |
|
Content-type | application/json; charset=UTF-8 |
|
Params | Id:id,name:name | Id:1,name:admin |
*Result | String |
|
4.1接口共用参数
内网测试服务器 |
|
|
| Host | 192.168.1.157 |
| Port | 8888 |
|
|
|
4.2 HttpClient 请求
源码使用HttpClient进行二进制数据传输
4.2.1上传upload
|
|
|
*url | http://host:port/fdfs/byte/upload |
|
method | post |
|
Content-type | application/octet-stream; charset=UTF-8 |
|
Params | byte[] |
|
*Result | String | 上传成功返回fileId |
4.2.2下载download
|
|
|
*url | http://host:port/fdfs/byte/download |
|
method | get |
|
Content-type | application/json; charset=UTF-8 |
|
Params | fileId:fileId | 上传成功时返回的fileId |
*Result | byte[] | getMethod.getResponseBody(); |
4.2.3删除delete
|
|
|
*url | http://host:port/fdfs/byte/delete |
|
method | get |
|
Content-type | application/json; charset=UTF-8 |
|
Params | fileId:fileId | 上传成功时返回的fileId |
*Result | String | -1 文件不存在 0 删除成功 2 删除失败 |
4.2.4查询queryFileInfo
|
|
|
*url | http://host:port/fdfs/byte/queryFileInfo |
|
method | get |
|
Content-type | application/json; charset=UTF-8 |
|
Params | fileId:fileId | 上传成功时返回的fileId |
*Result | json | {"crc32":-753150525, "fileSize":8611737, "sourceIpAddr":"192.168.1.185", "createTimestamp":1476696678000} |
4.3 Http客户端请求
客户端直接调用(不推荐使用)
4.3.1上传upload
|
|
|
*url | http://host:port/fdfs/file/upload |
|
method | post |
|
Content-type |
|
|
Params | file | <form action="/fileDFS/restful/fdfs/upload" enctype="multipart/form-data" method="post"> 上传文件1:<input type="file" name="fileName"><br/> <input type="submit" value="提交"> </form> |
*Result | String | 上传成功返回fileId |
4.3.2下载download
|
|
|
*url | http://host:port/fdfs/file/download |
|
method | get |
|
Content-type |
|
|
Params | fileId:fileId | 上传成功时返回的fileId |
*Result | void | getMethod.getResponseBody(); |
4.3.3删除delete
|
|
|
*url | http://host:port/fdfs/file/delete |
|
method | get |
|
Content-type |
|
|
Params | fileId:fileId | 上传成功时返回的fileId |
*Result | String | -1 文件不存在 0 删除成功 2 删除失败 |