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);

FastDFS.Client操作文件服务器的更多相关文章

  1. 实操:Could not autowire No beans of 'FastDFS Client' type found 的解决方法

    前言: 今天接手了同事之前做的一个小项目,里面涉及到了 FastDFS 的使用.但是当我在本地运行项目的时候,却报了 Could not autowire No beans of 'FastDFS C ...

  2. UWP开发技巧:实现SMB协议操作文件服务器文件

    问题来源 文件服务器文件夹操作在PC与Surface端确实还是和传统操作一样没什么区别,但是到了手机端与Surface Hub就没那么方便了,因为文件资源管理器Explorer根本没法添加网路硬盘.对 ...

  3. 使用Java High Level REST Client操作elasticsearch

    Java高级别REST客户端(The Java High Level REST Client)以后简称高级客户端,内部仍然是基于低级客户端.它提供了更多的API,接受请求对象作为参数并返回响应对象,由 ...

  4. 使用Java Low Level REST Client操作elasticsearch

    Java REST客户端有两种风格: Java低级别REST客户端(Java Low Level REST Client,以后都简称低级客户端算了,难得码字):Elasticsearch的官方low- ...

  5. FastDFS client for .net

    fastDfs Code: https://code.google.com/p/fastdfs/ FastDfs_Client_DotNet:https://code.google.com/p/fas ...

  6. 2、Zookeeper集群搭建、命令行Client操作

    zookeeper 集群最好是奇数台: 5台允许挂掉2台 4台只能允许挂掉1台 zjtest7-redis:/opt/zookeeper/bin# ./zkServer.sh status ZooKe ...

  7. 安装配置fastDFS文件服务器 - Linux

    一.配置linux环境 1.新建虚拟机 把上次安装的CentOS7的文件复制一份,并改名 打开VM>打开虚拟机,选择刚才复制好的虚拟机,并启动.这样做的目的主要是为了保留一份最基础的母本,为了将 ...

  8. 阿里云centos6.9搭建fastDFS文件服务器

    准备压缩包: 1.fastdfs-nginx-module_v1.16.tar.gz 2.FastDFS_v5.05.tar.gz 3.libfastcommonV1.0.7.tar.gz 4.ngi ...

  9. 搭建fastdfs文件服务器

    一.安装FastDFS环境 1.跟踪服务器(Tracker Server) tracker1:192.168.2.134 tracker2:192.168.2.135 2.存储服务器(Storage ...

随机推荐

  1. java反射,ReflectUtils

    public class ReflectUtils { /** * 通过构造函数实例化对象 * @param className 类的全路径名称 * @param parameterTypes 参数类 ...

  2. java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSession

    在配置一个springmvc+mybatis的项目时,总是有报一个错误: org.springframework.beans.factory.BeanCreationException: Error ...

  3. java的基本程序设计之个人总结要点

    java的基本程序设计之个人总结要点 这是个人看完java核心卷一书之后,罗列的一些比较重要的点子,希望共享给大家. [数值类型] 1.从java7开始,加上前缀0b就可以写二进制数,例如:0b100 ...

  4. 用:before :after 来写一些小特效

    提起:before :after首先想到的是 —— 用它来去浮动来我们来换个方式玩接下来展示三种用:before :after来实现的特效 希望能起到抛砖引玉的作用 <一>第一种就是常见的 ...

  5. mac系统下Ruby环境安装

    在我们编写代码过程中,会用到一系列的第三方开源类库,我们可以选择手动去一个个添加需要的库,但这非常麻烦.因此我们可以使用CocoaPods来帮助我们自动添加.使用CocoaPods需要先安装Ruby环 ...

  6. FPS中受伤UI在VR游戏中的实现思路

    FPS中受伤UI在VR游戏中的实现思路 希望实现的效果 这几天一直在尝试各种解决方案,现在算是不完美的解决啦,记录一下心路历程,思路有了算法都比较简单. V_1 玩家胶囊体指向的方向作为正方向,计算出 ...

  7. 策略模式(strategy pattern)

    策略模式在java集合中的TreeSet和TreeMap中得到了很好的应用,我们可以实现Comparator接口实现Compareto()方法来定义自己的排序规则,然后通过TreeSet,TreeMa ...

  8. Modified Least Square Method and Ransan Method to Fit Circle from Data

    In OpenCv, it only provide the function fitEllipse to fit Ellipse, but doesn't provide function to f ...

  9. maven增加自定义jar包

    1.博客来源: http://www.cnblogs.com/leiOOlei/p/3356834.html 导入平台SDK的方法 mvn install:install-file -DgroupId ...

  10. linux使用grep和find查找内容

    1,在某个路径下查文件. 在/etc下查找“*.log”的文件 find /etc -name “*.log” 2,扩展,列出某个路径下所有文件,包括子目录. find /etc -name “*” ...