Exemplo n.º 1
0
        /// <summary>
        /// SyncTest
        /// </summary>
        /// <returns></returns>
        private static void SyncTest()
        {
            StorageNode storageNode = FastDFSClient.GetStorageNode("group1");

            string[] files     = Directory.GetFiles("testimage", "*.jpg");
            string[] strArrays = files;
            for (int i = 0; i < strArrays.Length; i++)
            {
                string str1         = strArrays[i];
                var    fileStream   = new FileStream(str1, FileMode.Open);
                var    binaryReader = new BinaryReader(fileStream);
                byte[] numArray;
                try
                {
                    numArray = binaryReader.ReadBytes((int)fileStream.Length);
                }
                finally
                {
                    binaryReader.Dispose();
                }
                var str = FastDFSClient.UploadFile(storageNode, numArray, "jpg");
                Console.WriteLine(StorageLink + str);
                FastDFSClient.RemoveFile("group1", str);
                Console.WriteLine("FastDFSClient.RemoveFile" + str);
            }
        }
Exemplo n.º 2
0
 protected void rtpPicHistoryList_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     try
     {
         int FileHistoryID = e.CommandArgument.ToString().ConvertInt();
         resource_filehistory objPicHistory = objFileResourceRule.resource_filehistory.FirstOrDefault(s => s.FileHistoryID == FileHistoryID);
         string PicUrl = objPicHistory.PicUrl;
         if (PicUrl.IndexOf("M00") >= 0)
         {
             resource_filestoragepath objresource_filestoragepath = objFileResourceRule.resource_filestoragepath.FirstOrDefault(s => s.FileStoragePathID == "590e546a-4695-48ef-af7f-c8f6de287bc7");
             PicUrl = PicUrl.Substring(PicUrl.IndexOf("M00"));
             int i = PicUrl.IndexOf('?');
             if (i > 0)
             {
                 PicUrl = PicUrl.Substring(0, i);
             }
             FastDFSClient objFastDFSClient = new FastDFSClient(objresource_filestoragepath.StorageConfig, string.IsNullOrWhiteSpace(objresource_filestoragepath.StorageConfig));
             objFastDFSClient.RemoveFile("g1", PicUrl);
             objFileResourceRule.resource_filehistory.DeleteDataPrimaryKey(FileHistoryID.ToString());
             MessageDialog("删除成功");
         }
         else
         {
             MessageDialog("没有找到相应的删除处理方法,请与管理员联系");
         }
     }
     catch (Exception objExp)
     {
         Log.WriteLog("删除文件失败", objExp);
         MessageDialog("删除文件失败");
     }
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var config = FastDfsManager.GetConfigSection();

            StorageNode storageNode = null;

            var fileName = "";

            ConnectionManager.InitializeForConfigSection(config);

            do
            {
                // Console.WriteLine("\r\n1.Init");
                Console.WriteLine("\r\n");
                Console.WriteLine("1.GetAllStorageNode");
                Console.WriteLine("2.GetStorageNode");
                Console.WriteLine("3.UploadFile");
                Console.WriteLine("4.RemoveFile");

                Console.Write("请输入命令:");
                var cmd = Console.ReadLine();

                switch (cmd)
                {
                case "1":
                    var list = FastDFSClient.GetStorageNodes(config.GroupName);
                    foreach (var item in list)
                    {
                        Console.WriteLine(item.EndPoint.ToString());
                        Console.WriteLine(item.StorePathIndex);
                    }
                    break;

                case "2":
                    storageNode = FastDFSClient.GetStorageNode(config.GroupName);
                    Console.WriteLine(storageNode.GroupName);
                    Console.WriteLine(storageNode.EndPoint);
                    Console.WriteLine(storageNode.StorePathIndex);
                    break;

                case "3":
                    fileName = FastDFSClient.UploadFile(storageNode, File.ReadAllBytes("test.jpg"), "jpg");
                    Console.WriteLine(fileName);
                    break;

                case "4":
                    FastDFSClient.RemoveFile(config.GroupName, fileName);
                    break;
                }
            } while (true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 删除文件
 /// </summary>
 /// <param name="fileStream">文件流</param>
 /// <returns>返回主文件路径</returns>
 public static void RemoveFile(string fileName)
 {
     FastDFSClient.RemoveFile(groupName, fileName);
 }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            //===========================Initial========================================
            List <IPEndPoint> trackerIPs = new List <IPEndPoint>();
            IPEndPoint        endPoint   = new IPEndPoint(IPAddress.Parse("10.0.21.101"), 22122);

            trackerIPs.Add(endPoint);
            ConnectionManager.Initialize(trackerIPs);
            StorageNode node = FastDFSClient.GetStorageNode();

            //===========================UploadFile=====================================
            byte[] content  = null;
            string filename = @"D:\软件开发\OS\FastDFS\file\4.jpg";

            if (File.Exists(filename))
            {
                FileStream streamUpload = new FileStream(filename, FileMode.Open);
                using (BinaryReader reader = new BinaryReader(streamUpload))
                {
                    content = reader.ReadBytes((int)streamUpload.Length);
                }
            }
            //string fileName = FastDFSClient.UploadAppenderFile(node, content, "mdb");
            string fileName = FastDFSClient.UploadFile(node, content, "jpg");

            FastDFSClient.DownloadFileEx(node, fileName, @"D:\软件开发\OS\FastDFS\file", "5.jpg");

            Console.ReadKey();

            //===========================BatchUploadFile=====================================
            string[] _FileEntries = Directory.GetFiles(@"E:\fastimage\三维", "*.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);

            //===========================QueryFile=======================================
            fileName = "M00/00/00/wKhR6U__-BnxYu0eAxRgAJZBq9Q180.mdb";
            FDFSFileInfo fileInfo = FastDFSClient.GetFileInfo(node, fileName);

            Console.WriteLine(string.Format("FileName:{0}", fileName));
            Console.WriteLine(string.Format("FileSize:{0}", fileInfo.FileSize));
            Console.WriteLine(string.Format("CreateTime:{0}", fileInfo.CreateTime));
            Console.WriteLine(string.Format("Crc32:{0}", fileInfo.Crc32));
            //==========================AppendFile=======================================
            FastDFSClient.AppendFile("group1", fileName, content);
            FastDFSClient.AppendFile("group1", fileName, content);

            //===========================DownloadFile====================================
            fileName = "M00/00/00/wKhR6U__-BnxYu0eAxRgAJZBq9Q180.mdb";
            byte[] buffer = FastDFSClient.DownloadFile(node, fileName, 0L, 0L);
            if (File.Exists(@"D:\SZdownload.mdb"))
            {
                File.Delete(@"D:\SZdownload.mdb");
            }
            FileStream stream = new FileStream(@"D:\SZdownload.mdb", FileMode.CreateNew);

            using (BinaryWriter write = new BinaryWriter(stream, Encoding.BigEndianUnicode))
            {
                write.Write(buffer);
                write.Close();
            }
            stream.Close();
            //===========================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测试,直接下载=======================================
            WebClient web = new WebClient();

            web.DownloadFile("http://img13.360buyimg.com/da/g5/M02/0D/16/rBEDik_nOJ0IAAAAAAA_cbJCY-UAACrRgMhVLEAAD-J352.jpg", "C:\\abc.jpg");
            web.DownloadFile("http://192.168.81.233/M00/00/00/wKhR6VADbNr5s7ODAAIOGO1_YmA574.jpg", "C:\\abc.jpg");

            Console.WriteLine("Complete");
            Console.Read();
        }
        static void Main(string[] args)
        {
            #region 初始化
            // 所有 tracker 服务器的ip:port
            var trackerIPs = new List <IPEndPoint>()
            {
                new IPEndPoint(IPAddress.Parse("192.168.181.128"), 22122)
            };
            if (!ConnectionManager.Initialize(trackerIPs))
            {
                throw new Exception("fastDFS连接初始化失败!");
            }

            var node = FastDFSClient.GetStorageNode("group1");
            #endregion

            #region 小文件上传
            //var uploadingfilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\1.jpg");
            //var uploadedfileUrl1 = MyFastDFSClient.UploadFile(node, uploadingfilePath);
            //Console.WriteLine($"小文件已上传,Url 为:{uploadedfileUrl1}");


            //var slaveFileName = FastDFSClient.UploadSlaveFile("group1", content, fileName, "-part1", "jpg");
            #endregion

            #region 大文件上传



            #endregion

            #region 文件查询
            var queryFileUrl = "M00/00/00/wKi1gF5LsuiAdeRbAAYD2YvCnl8857.jpg";
            try
            {
                var fileInfo = FastDFSClient.GetFileInfo(node, queryFileUrl);
                Console.WriteLine($"文件大小:{fileInfo.FileSize}");
                Console.WriteLine($"文件创建时间:{fileInfo.CreateTime.AddHours(8):yyyy-MM-dd HH:mm:ss}");
            }
            catch (FDFSException ex)
            {
                Console.WriteLine($"文件不存在:{queryFileUrl}");
                Console.WriteLine($"Message:{ex.Message}");
            }

            #endregion

            #region 小文件下载
            var downloadingfileUrl = "M00/00/00//wKi1gF5LsuiAdeRbAAYD2YvCnl8857.jpg";
            var localPath          = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"..\..\download\1{Path.GetExtension(downloadingfileUrl)}");

            // 出现图片内容丢失
            //var downloadingfileBytes = FastDFSClient.DownloadFile(node, downloadingfileUrl);
            //File.WriteAllBytes(localPath, downloadingfileBytes);

            //var downloadingfileUrl = $"http://192.168.181.128:8888/group1/{downloadingfileUrl}";
            //using (WebClient web = new WebClient())
            //{
            //    Directory.CreateDirectory(Path.GetDirectoryName(localPath));
            //    web.DownloadFile(downloadingfileUrl, localPath);

            //    //Console.WriteLine("文件已下载完毕,稍后将自动打开。。。");
            //    //Process.Start("explore.exe", localPath);
            //}

            #endregion

            #region 大文件下载

            #endregion

            #region 文件删除
            var removingfileName = "M00/00/00/wKi1gF5LsuiAdeRbAAYD2YvCnl8857.jpg";
            try
            {
                FastDFSClient.RemoveFile(node.GroupName, removingfileName);
                Console.WriteLine($"文件已删除:{removingfileName}");
            }
            catch (FDFSException ex)
            {
                Console.WriteLine($"文件不存在:{queryFileUrl}");
                Console.WriteLine($"Message:{ex.Message}");
            }
            #endregion

            Console.WriteLine("ending........................");
            Console.ReadKey();
        }
Exemplo n.º 7
0
 public void RemoveFile(string fileID)
 {
     FastDFSClient.RemoveFile(config.GroupName, fileID);
 }