FASTDFS .net 客户端

时间:2021-10-31 02:30:34

FastDFS .net 客户端目前还比较少,而且使用大部分没有原生提供的方便

推荐一个比较方便的

下载地址:

https://www.nuget.org/packages/NengLong.CMP.FastDFSClient/1.0.1

使用的技术是IKVM 可以写和原生java 一样的文件处理了,比较方便

简单的例子如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using org.csource.fastdfs; using System.IO;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{ ClientGlobal.init("client.conf"); // 初始配置加载tracker信息,可以参考javaAPI
TrackerClient trackerClient; TrackerServer trackerServer; StorageClient1 storageClient;
StorageServer storageServer;
trackerClient = new TrackerClient();
trackerServer = trackerClient.getConnection(); storageServer = trackerClient.getStoreStorage(trackerServer);
storageClient = new StorageClient1(trackerServer, storageServer); // 存储操作类生成 FileStream fs = new FileStream("client.conf", FileMode.OpenOrCreate, FileAccess.Read); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length);
fs.Close();
var fileinfo = storageClient.upload_file1("dd.xlsx", "xlsx", null); // 上传文件
Console.WriteLine(fileinfo);
var data= storageClient.download_file1(fileinfo); // 下载文件 var dat2 = storageClient.download_file1("group1/M00/00/00/ZciJUFcwnPqATS68AAB4AHKdIvA163.tar"); // 下载已有文件
FileStream fs2 = new FileStream("dddd.xlsx", FileMode.OpenOrCreate); BinaryWriter bw = new BinaryWriter(fs2);
bw.Write(data); bw.Close(); fs2.Close(); FileStream fs3 = new FileStream("demo.tar", FileMode.OpenOrCreate); BinaryWriter bw2 = new BinaryWriter(fs3);
bw2.Write(dat2); fs3.Close(); fs2.Close();
Console.ReadLine(); }
}
}