1、配置文件设置

<configSections>
<section name="fastdfs" type="FastDFS.Client.Config.FastDfsConfigurationSectionHandler, FastDFS.Client" />
</configSections> <fastdfs>
<FastDfsConfig GroupName="group1">
<FastDfsServer IpAddress="192.168.88.103" Port="22122" />
</FastDfsConfig>
</fastdfs>

2、FastDFS.Client API调用

上传:

//文件保存到FastDFS服务器
var config = FastDfsManager.GetConfigSection();
ConnectionManager.InitializeForConfigSection(config);
StorageNode storageNode = FastDFSClient.GetStorageNode(config.GroupName); string filePath = FastDFSClient.UploadFile(storageNode, file.Data, file.Extension.Replace(".", ""));

下载:

private Task<byte[]> DownloadFileAsyn(string filePath)
{
return Task.Run(() =>
{
List<byte> content = new List<byte>();
var config = FastDfsManager.GetConfigSection();
ConnectionManager.InitializeForConfigSection(config);
StorageNode storageNode = FastDFSClient.GetStorageNode(config.GroupName);
FDFSFileInfo fileInfo = FastDFSClient.GetFileInfo(storageNode, filePath);
if (fileInfo.FileSize >= ) //文件内容大于1024字节时,需要分批下载
{
long offset = , len = ;
while (len > )
{
byte[] buffer = FastDFSClient.DownloadFile(storageNode, filePath, offset, len);
content.AddRange(buffer);
offset += len;
len = Math.Min(fileInfo.FileSize - offset, );
}
}
else
{
content.AddRange(FastDFSClient.DownloadFile(storageNode, filePath));
} return content.ToArray();
});
}

删除:

         // 从FastDFS服务器删除
var config = FastDfsManager.GetConfigSection();
ConnectionManager.InitializeForConfigSection(config);
FastDFSClient.RemoveFile(config.GroupName, path);

最新文章

  1. bzoj 4003
  2. 【JAVA之泛型】
  3. android 判断屏幕是否亮着
  4. 18种CSS3loading效果完整版,兼容各大主流浏览器,提供在线小工具使用
  5. 管理员必备的20个Linux系统监控工具
  6. android webview js alert对话框 不能弹出 解决办法
  7. cloud-utils cloud-utils-growpart cloud-init
  8. 【AngularJS】——0.分析
  9. 了解HTML的代码注释
  10. 11G在线重建索引
  11. (转载)iscroll.js的使用
  12. Android布局_LinearLayout布局
  13. CSS3制作日历
  14. TestNG简介与安装步骤
  15. Bootstrap全局CSS样式之排版
  16. ubuntu12.04:Mysql数据库:自动安装
  17. 浅谈OA系统与Portal门户的区别
  18. Spring学习之旅(一)极速创建Spring框架java工程项目
  19. Spark思维导图之性能优化
  20. Python3+Selenium环境配置

热门文章

  1. 学习总结——Selenium元素定位
  2. MFC 自绘按钮 消息响应
  3. LR12.53—第4课:准备Vuser脚本进行负载测试
  4. Spark Streaming源码解读之Executor容错安全性
  5. 特殊js事件
  6. 多行SQL语句拼成一条数据
  7. 深入jQuery中的Callbacks()
  8. Apache 的ab压力测试工具
  9. AIX下安装bash
  10. c#接口容易被忽视的问题