FastDFS.Client操作文件服务器
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操作文件服务器的更多相关文章
- 实操:Could not autowire No beans of 'FastDFS Client' type found 的解决方法
前言: 今天接手了同事之前做的一个小项目,里面涉及到了 FastDFS 的使用.但是当我在本地运行项目的时候,却报了 Could not autowire No beans of 'FastDFS C ...
- UWP开发技巧:实现SMB协议操作文件服务器文件
问题来源 文件服务器文件夹操作在PC与Surface端确实还是和传统操作一样没什么区别,但是到了手机端与Surface Hub就没那么方便了,因为文件资源管理器Explorer根本没法添加网路硬盘.对 ...
- 使用Java High Level REST Client操作elasticsearch
Java高级别REST客户端(The Java High Level REST Client)以后简称高级客户端,内部仍然是基于低级客户端.它提供了更多的API,接受请求对象作为参数并返回响应对象,由 ...
- 使用Java Low Level REST Client操作elasticsearch
Java REST客户端有两种风格: Java低级别REST客户端(Java Low Level REST Client,以后都简称低级客户端算了,难得码字):Elasticsearch的官方low- ...
- FastDFS client for .net
fastDfs Code: https://code.google.com/p/fastdfs/ FastDfs_Client_DotNet:https://code.google.com/p/fas ...
- 2、Zookeeper集群搭建、命令行Client操作
zookeeper 集群最好是奇数台: 5台允许挂掉2台 4台只能允许挂掉1台 zjtest7-redis:/opt/zookeeper/bin# ./zkServer.sh status ZooKe ...
- 安装配置fastDFS文件服务器 - Linux
一.配置linux环境 1.新建虚拟机 把上次安装的CentOS7的文件复制一份,并改名 打开VM>打开虚拟机,选择刚才复制好的虚拟机,并启动.这样做的目的主要是为了保留一份最基础的母本,为了将 ...
- 阿里云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 ...
- 搭建fastdfs文件服务器
一.安装FastDFS环境 1.跟踪服务器(Tracker Server) tracker1:192.168.2.134 tracker2:192.168.2.135 2.存储服务器(Storage ...
随机推荐
- 如何获取TypedArray?
当我们需要自定义控件的时候经常会使用到TypedArray这个类,使用完之后必须调用recycler()函数.... 但是如何获取呢? 有如下几个方式: context(实际最后调用的是context ...
- oracle修改字段长度
alter table 表名 modify (字段名 字段类型长度);alter table cachemsg modify (callernum varchar(40));
- 用VBS实现公司自动打卡
公司每天要求早晚打卡,方式是登录某一个页面,然后点击上面的圈圈,如下图: 每天都要打开书签,登录这个页面,然后打卡...这么重复性的工作,怎么能是程序员天天干的事情呢(其实是我太懒了),那么就尝试让程 ...
- cs11_c++_lab7
wcount.cc #include <iostream> #include <map> #include <string> #include <algori ...
- 利用nodejs的cheerio抓取网站数据
/*引入模块*/ var http = require('http') var url = 'http://www.cnblogs.com/txxt' var cheerio = require('c ...
- Android IOS WebRTC 音视频开发总结(二五)-- webrtc优秀资源汇总
本文主要整理一些webrtc相关资料供学习(会持续更新),转载请说明出处,文章来自博客园RTC.Blacker,欢迎关注微信公众号:blackerteam ---------------------- ...
- Spring异常抛出触发事务回滚
Spring.EJB的声明式事务默认情况下都是在抛出unchecked exception后才会触发事务的回滚 /** * 如果在spring事务配置中不为切入点(如这里的切入点可以定义成test*) ...
- git乱码问题解决
etc\gitconfig文件中增加以下内容: [gui] encoding = utf-8 [i18n] commitencoding = gbk [svn] pathnam ...
- 免费而优秀的图表JS插件
1.百度的Echart ECharts,缩写来自Enterprise Charts,是百度推出的一款开源的,商业级数据图表,它最初是为了满足百度公司商业体系里各种业务系统(如凤巢.广告管家等等)的报表 ...
- python操作mysql数据库
连接数据库 输入值 存入数据库 关闭 import string import mysql.connector conn=mysql.connector.connect(user='root',pas ...