Exemplo n.º 1
0
        private static async Task UploadAppendFile()
        {
            var         testBytes   = Encoding.UTF8.GetBytes("123456789");
            StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1", "server");

            var filename = await FastDFSClient.UploadAppenderFileAsync(storageNode, testBytes.Take(6).ToArray(), "", "default");

            FDFSFileInfo fileInfo = await FastDFSClient.GetFileInfoAsync(storageNode, filename, "default");

            if (fileInfo == null)
            {
                Console.WriteLine($"GetFileInfoAsync Fail, path: {filename}");
                return;
            }

            Console.WriteLine("FileName:{0}", filename);
            Console.WriteLine("FileSize:{0}", fileInfo.FileSize);
            Console.WriteLine("CreateTime:{0}", fileInfo.CreateTime);
            Console.WriteLine("Crc32:{0}", fileInfo.Crc32);

            var appendBytes = testBytes.Skip((int)fileInfo.FileSize).ToArray();
            await FastDFSClient.AppendFileAsync("group1", filename, appendBytes, "default");

            var test = await HttpClient.GetByteArrayAsync(StorageLink + filename);

            if (Encoding.UTF8.GetString(test) == Encoding.UTF8.GetString(testBytes))
            {
                Console.WriteLine($"UploadAppendFile Success");
            }
            else
            {
                throw new ApplicationException($"UploadAppendFile Fail : Bytes Diff ");
            }
            await FastDFSClient.RemoveFileAsync("group1", filename, "default");
        }
Exemplo n.º 2
0
        protected static async Task BigFileAppendUploadDownLoad()
        {
            var         temp        = Enumerable.Repeat((byte)99, 1024 * 1024 * 100);
            var         testBytes   = temp.ToArray();
            StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1", "default");


            var filename = await FastDFSClient.UploadAppenderFileAsync(storageNode, testBytes.Take(1024 * 1024 * 2).ToArray(), "txt", "default");

            for (int i = 0; i < 49; i++)
            {
                FDFSFileInfo fileInfo = await FastDFSClient.GetFileInfoAsync(storageNode, filename, "default");

                var appendBytes = testBytes.Skip((int)fileInfo.FileSize).Take(1024 * 1024 * 2).ToArray();
                await FastDFSClient.AppendFileAsync("group1", filename, appendBytes, "default");
            }

            using (var fileStream = File.OpenWrite("c:\\fastdfs_test.txt"))
            {
                for (int i = 0; i < 50; i++)
                {
                    var buffer = await FastDFSClient.DownloadFileAsync(storageNode, filename, "default",
                                                                       1024 * 1024 * 2 *i,
                                                                       1024 * 1024 * 2);

                    fileStream.Write(buffer, 0, buffer.Length);
                }
            }

            await FastDFSClient.RemoveFileAsync("group1", filename, "default");

            temp      = null;
            testBytes = null;
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetFileInfoAsync([FromRoute] string filename)
        {
            filename = HttpUtility.UrlDecode(filename);
            //StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync(NodeGroup);
            StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync();

            FDFSFileInfo fileInfo = await FastDFSClient.GetFileInfoAsync(storageNode, filename);

            return(Ok(fileInfo));
        }
Exemplo n.º 4
0
        /// <summary>
        /// TestGetFileInfo
        /// </summary>
        private static async Task TestGetFileInfo()
        {
            StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1");

            var          str      = "M00/0E/82/CgE-EFsTqKmAEHO7AADMG7XS9Fc7491.jpg";
            FDFSFileInfo fileInfo = await FastDFSClient.GetFileInfoAsync(storageNode, str);

            if (fileInfo == null)
            {
                Console.WriteLine("Not Exist");
                return;
            }
            Console.WriteLine("FileName:{0}", str);
            Console.WriteLine("FileSize:{0}", fileInfo.FileSize);
            Console.WriteLine("CreateTime:{0}", fileInfo.CreateTime);
            Console.WriteLine("Crc32:{0}", fileInfo.Crc32);

            Console.WriteLine("Complete");
        }
Exemplo n.º 5
0
        /// <summary>
        /// TestGetFileInfo
        /// </summary>
        private static async Task TestGetFileInfo()
        {
            StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1");

            var str      = "http://locahost/group1/M00/00/00/oYYBAFvcGZ2AGBAbAAAUa4KwmUU269.png";
            var fileInfo = await FastDFSClient.GetFileInfoAsync(str);

            if (fileInfo == null)
            {
                Console.WriteLine("Not Exist");
                return;
            }
            Console.WriteLine("FileName:{0}", str);
            Console.WriteLine("FileSize:{0}", fileInfo.FileSize);
            Console.WriteLine("CreateTime:{0}", fileInfo.CreateTime);
            Console.WriteLine("Crc32:{0}", fileInfo.Crc32);

            Console.WriteLine("Complete");
        }
        /// <summary>
        /// 获取对象流
        /// </summary>
        /// <param name="groupName">组名称</param>
        /// <param name="objectName">对象名称</param>
        /// <returns>对象流</returns>
        public async Task <Stream> GetObjectStreamAsync(string objectName, string groupName = "")
        {
            RestoreFileName(objectName, out string fileName, out groupName);
            var storageNode = await GetStorageNodeAsync(groupName);

            FDFSFileInfo fileInfo = await FastDFSClient.GetFileInfoAsync(storageNode, fileName);

            Stream stream = new MemoryStream();
            int    limit  = 1024 * 100;//每次获取100KB的数据

            //如果文件大小大于100KB  分次写入
            if (fileInfo.FileSize >= limit)
            {
                long offset = 0;
                long len    = limit;
                while (len > 0)
                {
                    byte[] buffer = await FastDFSClient.DownloadFileAsync(storageNode, fileName, offset, len);

                    stream.Write(buffer, 0, int.Parse(len.ToString()));
                    stream.Flush();
                    offset += len;
                    len     = (fileInfo.FileSize - offset) >= limit ? limit : (fileInfo.FileSize - offset);
                }
            }
            else
            {
                //如果文件大小小小于100KB  直接写入文件
                byte[] buffer = await FastDFSClient.DownloadFileAsync(storageNode, fileName);

                stream.Write(buffer, 0, buffer.Length);
                stream.Flush();
            }

            stream.Seek(0, SeekOrigin.Begin);
            return(stream);
        }
Exemplo n.º 7
0
 public Task <QUERY_FILE_INFO_Result> GetFileInfo(string fileUrl)
 {
     return(FastDFSClient.GetFileInfoAsync(fileUrl));
 }