FastDFS的配置、部署与API使用解读(8)FastDFS多种文件上传接口详解(转)

1、StorageClient与StorageClient1的区别

相信使用happy_fish的FastDFS的童鞋们,一定都熟悉StorageClient了,或者你熟悉的是StorageClient1,两者有什么区别呢?

我们在前面的几篇博文中已经知道,FastDFS存储文件时,是将 FastDFS存储到某个Group的某个Storage的某个路径下。如果你在Storage Server上设置的是两层目录结构的话,则一个文件上传到FastDFS后的File ID一般形如"group1/M01/00/2A/rBAsVk8ORy2Nf9EoAAIRKo2Da7U901.jpg"形式。其中的 “group1”称为Group Name,后段的“M01/00/08/rBAsVk8ORy2Nf9EoAAlRKo2Da7U901.jpg"称为File Name。

知道了这些后,我们就可以讨论StorageClient和 StorageClient1的区别了。StorageClient中是将File ID用Group Name和File Name两部分来表示的,而StorageClient1中是将Group Name和File Name统一起来处理的。其实通过分析FastDFS Java Client的源码可以发现,StorageClient1是StorageClient的一个子类。

 

    public class StorageClient1 extends StorageClient {  
          ...  
    }  

 

 StorageClient1中的upload_file1(...)方法的实现,都是在调用this.upload_file(...),将返回的Group Name和File Name组合起来返回的。


2、多种文件上传接口

目前FastDFS Java Client API的最新版本是1.19,该版本中有如下这些上传API(这里以Storage Client1为例):

 

/*方法1*/upload_file1(byte[] file_buff, String file_ext_name, NameValuePair[] meta_list);  
/*方法2*/upload_file1(String group_name, byte[] file_buff, String file_ext_name, NameValuePair[] meta_list);  
/*方法3*/upload_file1(String master_file_id, String prefix_name, byte[] file_buff, int offset, int length, String file_ext_name, NameValuePair[] meta_list);  
/*方法4*/upload_file1(String master_file_id, String prefix_name, byte[] file_buff, String file_ext_name, NameValuePair[] meta_list);  
  
/*方法5*/upload_file1(String group_name, long file_size, UploadCallback callback, String file_ext_name, NameValuePair[] meta_list);  
/*方法6*/upload_file1(String master_file_id, String prefix_name, long file_size, UploadCallback callback, String file_ext_name, NameValuePair[] meta_list);  
  
/*方法7*/upload_file1(String local_file_name, String file_ext_name, NameValuePair[] meta_list);  
/*方法8*/upload_file1(String group_name, String local_file_name, String file_ext_name, NameValuePair[] meta_list);  
/*方法9*/upload_file1(String master_file_id, String prefix_name, String local_file_name, String file_ext_name, NameValuePair[] meta_list); 

 

 

(1)多种上传格式

方法1-4是上传File Buffer(字节数组);方法5-6是通过回调的方式上传文件流(以后的文章中会解释),方法7-9是上传本地文件。


(2)多种上传方式

下面我们把这几种上传的接口的参数总结一下,方便大家使用API。

 

 Group NameExtensionMeta ListMaster File IDPrefix NameOffsetLengthSizeFormat
Method 1      Buffer
Method 2     Buffer
Method 3  Buffer
Method 4    Buffer
Method 5    Stream
Method 6   Stream
Method 7      Local
Method 8     Local
Method 9    Local

所有方式都可以携带参数extension和meta list。另外通过回调上传流的方式,必须给出文件大小的参数。

StorageClient1的上传方法,返回值是String,StorageClient的上传方法,返回值是String[]。

 

转载于:https://www.cnblogs.com/sandea/p/4439295.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
文本格式不能很好显示,请见谅(附件里有比较齐整的excel表格统计) 大小类型 输类型 api方法 文件大小 花费时间 速率byte/ms 速率mb/s 缓存数组 次数 备注 大文件 下载 download_file(group_name, remote_filename, localFile) 1073741824(约1G) 28343ms 37883 36.12804413 无 1 下载 download_file(group_name, remote_filename , downloadStream) 1073741824(约1G) 29195ms 36778 35.07423401 0 1 fastDFS的DownloadStream,FileOutputStream 下载 download_file(group_name, remote_filename , downloadStream) 1073741824(约1G) 24352ms 44092 42.04940796 2K 1 fastDFS的DowloadStream,BufferedOutputStream 下载 download_file(group_name, remote_filename , DownloadCallback) 1073741824(约1G) 24831ms 43241 41.23783112 2K 1 实现DownloadCallback,BufferedOutputStream 下载 download_file(group_name, remote_filename , DownloadCallback) 1073741824(约1G) 25922ms 41422 39.50309753 8K 1 实现DownloadCallback,BufferedOutputStream 普通文件 下载 download_file(group_name, remote_filename, localFile) 59113472(约56M) 382ms 154747 147.5782394 无 1 下载 download_file(group_name, remote_filename , downloadStream) 59113472(约57M) 369ms 160199 152.7776718 0 1 fastDFS的DownloadStream,FileOutputStream 下载 download_file(group_name, remote_filename , downloadStream) 59113472(约58M) 499ms 118702 113.2030487 2K 1 fastDFS的DowloadStream,BufferedOutputStream 下载 download_file(group_name, remote_filename , DownloadCallback) 59113472(约59M) 592ms 99853 95.22724152 2K 1 实现DownloadCallback,BufferedOutputStream 下载建议:100M内数据使用fastDFS提供的DownloadStream;大于1G的数据,使用BufferedOutputStream和DowloadStream

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值