FastDFS NET示例
Program.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using FastDFS.Client;
using System.Drawing;
namespace FastDFS
{
internal class Program
{
private static void Main(string[] args)
{
//===========================初始化========================================
var trackerIPs = new List<IPEndPoint>();
var endPoint = new IPEndPoint(IPAddress.Parse("193.112.***.225"), 22122);
trackerIPs.Add(endPoint);
ConnectionManager.Initialize(trackerIPs);
var node = FastDFSClient.GetStorageNode("group1");
//===========================上傳檔案=====================================
byte[] content = null;
if (File.Exists(@"E:\JSON.pdf"))
{
FileStream streamUpload = new FileStream(@"E:\JSON.pdf", FileMode.Open);
using (BinaryReader reader = new BinaryReader(streamUpload))
{
content = reader.ReadBytes((int)streamUpload.Length);
}
}
//主檔案
string fileName = FastDFSClient.UploadFile(node, content, "pdf");
//UploadFileByName
//string fileName1 = FastDFSClient.UploadFileByName(node, @"D:\計算機基礎.doc");
//從檔案
string slavefileName = FastDFSClient.UploadSlaveFile("group1", content, fileName, "-part1", "pdf");
//===========================批量上傳檔案=====================================
string[] _FileEntries = Directory.GetFiles(@"E:\圖片\png", "*.jpg");
DateTime start = DateTime.Now;
foreach (string file in _FileEntries)
{
string name = Path.GetFileName(file);
content = null;
FileStream streamUpload = new FileStream(file, FileMode.Open);
using (BinaryReader reader = new BinaryReader(streamUpload))
{
content = reader.ReadBytes((int)streamUpload.Length);
}
//string fileName = FastDFSClient.UploadAppenderFile(node, content, "mdb");
fileName = FastDFSClient.UploadFile(node, content, "jpg");
}
DateTime end = DateTime.Now;
TimeSpan consume = ((TimeSpan)(end - start));
double consumeSeconds = Math.Ceiling(consume.TotalSeconds);
//===========================查詢檔案=======================================
fileName = "M00/00/00/rBAAC1rA21SAULJwAAoTzEG_OEk868.pdf";
//http://193.112.***.225/group1/M00/00/00/rBAAC1rA21SAULJwAAoTzEG_OEk868.pdf
//rBAAC1rA21SAULJwAAoTzEG_OEk868 - part1.pdf
//rBAAC1rA26iAWFB7AACXK3PhcOQ326.jpg
//rBAAC1rA27CAHqf4AAAUBnpdd - Q710.jpg
//rBAAC1rA28WAUmITAABKJd12G1A489.jpg
var fileInfo = FastDFSClient.GetFileInfo(node, fileName);
Console.WriteLine("FileName:{0}", fileName);
Console.WriteLine("FileSize:{0}", fileInfo.FileSize);
Console.WriteLine("CreateTime:{0}", fileInfo.CreateTime);
Console.WriteLine("Crc32:{0}", fileInfo.Crc32);
//==========================追加檔案=======================================
FastDFSClient.AppendFile("group1", fileName, content);
FastDFSClient.AppendFile("group1", fileName, content);
//===========================下載檔案====================================
//===========================RemoveFile=======================================
FastDFSClient.RemoveFile("group1", fileName);
//===========================Http測試,流讀取=======================================
string url = "http://img13.360buyimg.com/da/g5/M02/0D/16/rBEDik_nOJ0IAAAAAAA_cbJCY-UAACrRgMhVLEAAD-J352.jpg";
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
Image myImage = Image.FromStream(res.GetResponseStream());
myImage.Save("c:\\fast.jpg");//儲存
//===========================Http測試,直接下載=======================================
using (WebClient web = new WebClient())
{
web.DownloadFile("http://193.112.***.225/group1/M00/00/00/rBAAC1rA21SAULJwAAoTzEG_OEk868.pdf", "E:\\abc.pdf");
web.DownloadFile("http://193.112.***.225/group1/M00/00/00/rBAAC1rA26iAWFB7AACXK3PhcOQ326.jpg", "E:\\abc.jpg");
}
//===========================防盜鏈請求=======================================
start = new DateTime(1970, 1, 1);
end = DateTime.Now;
consume = (TimeSpan)(end - start);
int ts = (int)(consume.TotalSeconds);
string pwd = FastDFS.Client.Util.GetToken("M00/03/81/wKhR6VAh0sfyH0AxAABYAMjfFsM301-part1.doc", ts, "FastDFS1qaz2wsxsipsd");
string anti_steel_url = "http://192.168.81.233/M00/03/81/wKhR6VAh0sfyH0AxAABYAMjfFsM301-part1.doc?token=" + pwd + "&ts=" + ts;
string url1 = "http://192.168.81.233/M00/01/E0/wKhR6VANJBiInHb5AAClVeZnxGg341.pdf";
using (WebClient web = new WebClient())
{
web.DownloadFile(anti_steel_url, "C:\\salve.doc");
}
Console.WriteLine("完成");
Console.Read();
}
}
}
相關文章
- .Net Core中更高階的AutoMapper示例APP
- ML.NET呼叫Tensorflow模型示例——MNIST模型
- fastdfs管理工具Go-fastdfs-web 安裝教程ASTGoWeb
- fastdfs資料遷移以及fastdfs問題排查記錄AST
- linux安裝fastdfsLinuxAST
- FastDFS 技術整理AST
- 一、 Fastdfs介紹AST
- 三、 FastDFS功能原理AST
- ML.NET 示例:聚類之鳶尾花聚類
- JSON.NET與LINQ序列化示例JSON
- FastDFS-nginx外掛作為FastDFS客戶端訪問ASTNginx客戶端
- 【FastDFS】SpringBoot整合FastDFS實戰,我只看這一篇!!ASTSpring Boot
- 分散式檔案儲存FastDFS(七)FastDFS配置檔案詳解分散式AST
- ML.NET 示例:深度學習之整合TensorFlow深度學習
- ML.NET 示例:推薦之矩陣分解矩陣
- FastDFS入門小DemoAST
- FastDFS簡介,運用AST
- 常用設計模式之.Net示例程式碼合集設計模式
- csredis-in-asp.net core理論實戰-使用示例RedisASP.NET
- ML.NET 示例:迴歸之價格預測
- ML.NET 示例:迴歸之銷售預測
- ML.NET 示例:推薦之場感知分解機
- DFS 避坑手記 (docker 搭建 fastDFS 教程 / 在 CentOS 上搭建 FastDFS+nginx)DockerASTCentOSNginx
- spring-boot 中使用 FastDFSSpringbootAST
- Fastdfs資料遷移方案AST
- CentOS 7.0 之 FastDFS安裝CentOSAST
- 用 let's Encrypt 實現 HTTPS 示例( fasthttp 與net/http)HTTPAST
- ML.NET 示例:推薦之One Class 矩陣分解矩陣
- FastDFS依賴無法匯入AST
- Laravel 使用 FastDFS 上傳圖片LaravelAST
- springboot(十八):使用Spring Boot整合FastDFSSpring BootAST
- 【FastDFS】小夥伴們說在CentOS 8伺服器上搭建FastDFS環境總報錯?ASTCentOS伺服器
- FastDFS視訊教程-如何用FastDFS一步步搭建檔案管理系統AST
- ASP.NET CORE微信支付回撥示例程式碼ASP.NET
- DotNetty關鍵概念及簡單示例(基於NET5)Netty
- ML.NET 示例:多類分類之問題分類
- ML.NET 示例:多類分類之鳶尾花分類
- 吐槽net下沒有靠譜的FastDFS的sdk之使用thrift實現JAVA和C#互通ASTJavaC#