/// <summary> /// SyncTest /// </summary> /// <returns></returns> private static void SyncTest() { StorageNode storageNode = FastDFSClient.GetStorageNodeAsync("group1", "server").GetAwaiter().GetResult(); 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.UploadFileAsync(storageNode, numArray, "jpg", "default").GetAwaiter().GetResult(); Console.WriteLine(StorageLink + str); FastDFSClient.RemoveFileAsync("group1", str, "default").GetAwaiter().GetResult();; Console.WriteLine("FastDFSClient.RemoveFile" + str); } }
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; }
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"); }
/// <summary> /// 通过文件名删除对应的文件 /// </summary> /// <param name="objectName">对象名称</param> /// <param name="groupName">分组名称</param> /// <returns>是否成功</returns> public async Task <bool> DeleteObjectByNameAsync(string objectName, string groupName = "") { RestoreFileName(objectName, out string fileName, out groupName); await FastDFSClient.RemoveFileAsync(groupName, fileName); return(true); }
public async Task <IActionResult> DeleteFileAsync([FromQuery] string filename) { filename = HttpUtility.UrlDecode(filename); await FastDFSClient.RemoveFileAsync(NodeGroup, filename); return(Ok()); }
/// <summary> /// UploadAsync2 /// </summary> /// <param name="storageLink"></param> /// <param name="fileBytes"></param> /// <returns></returns> private static async Task UploadAsync2(string storageLink, byte[] fileBytes) { StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1", "default"); var str = await FastDFSClient.UploadFileAsync(storageNode, fileBytes, "jpg", "default"); Console.WriteLine(storageLink + str); await FastDFSClient.RemoveFileAsync("group1", str, "default"); Console.WriteLine("FastDFSClient.RemoveFile" + str); }
/// <summary> /// UploadAsync2 /// </summary> /// <param name="storageLink"></param> /// <param name="fileBytes"></param> /// <returns></returns> private static async Task UploadAsync2(string storageLink, Stream stream) { StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1"); var str = await FastDFSClient.UploadFileAsync(storageNode, stream, "jpg", CancellationToken.None); Console.WriteLine(storageLink + str); stream.Dispose(); await FastDFSClient.RemoveFileAsync("group1", str, CancellationToken.None); Console.WriteLine("FastDFSClient.RemoveFile" + str); }
protected static async Task BigFileUploadDownLoad() { var temp = Enumerable.Repeat((byte)99, 1024 * 1024 * 100); var testBytes = temp.ToArray(); StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1", "default"); var filename = await FastDFSClient.UploadFileAsync(storageNode, testBytes, "txt", "default"); using (var fileStream = File.OpenWrite("c:\\fastdfs_test.txt")) { await FastDFSClient.DownloadFileAsync(storageNode, filename, new StreamDownloadCallback(fileStream), "default"); } await FastDFSClient.RemoveFileAsync("group1", filename, "default"); temp = null; testBytes = null; }
/// <summary> /// UploadAsync /// </summary> /// <param name="storageLink"></param> /// <returns></returns> private static async Task UploadAsync(string storageLink) { StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync("group1", "server"); string[] files = Directory.GetFiles("testimage", "*.jpg"); string[] strArrays = files; for (int i = 0; i < strArrays.Length; i++) { string str1 = strArrays[i]; var numArray = GetFileBytes(str1); var str = await FastDFSClient.UploadFileAsync(storageNode, numArray, "jpg", "default"); Console.WriteLine(storageLink + str); await FastDFSClient.RemoveFileAsync("group1", str, "default"); Console.WriteLine("FastDFSClient.RemoveFile" + str); } }
public static async Task <bool> RemoveAsync(string path) { var arr = path.Split("/"); var groupName = arr[0]; path = path.Remove(arr[0].Length); try { await FastDFSClient.RemoveFileAsync(groupName, path); return(true); } catch (Exception) { return(false); } }
/// <summary> /// SyncTest /// </summary> /// <returns></returns> private static void SyncTest() { StorageNode storageNode = FastDFSClient.GetStorageNodeAsync("group1").GetAwaiter().GetResult(); 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, FileAccess.Read); var str = FastDFSClient.UploadFileAsync(storageNode, fileStream, "jpg", CancellationToken.None ).GetAwaiter().GetResult(); fileStream.Dispose(); Console.WriteLine(StorageLink + str); FastDFSClient.RemoveFileAsync("group1", str, CancellationToken.None).GetAwaiter().GetResult();; Console.WriteLine("FastDFSClient.RemoveFile" + str); } }
/// <summary> /// UploadAsync /// </summary> /// <param name="storageLink"></param> /// <returns></returns> private static async Task UploadAsync(string storageLink) { StorageNode storageNode = await FastDFSClient.GetStorageNodeAsync(group); string[] files = Directory.GetFiles(@"C:\Users\Administrator.DESKTOP-LOM86CH\Desktop\images"); string[] strArrays = files; for (int i = 0; i < strArrays.Length; i++) { string str1 = strArrays[i]; var numArray = GetFileBytes(str1); //务必保存此文件路径 var str = await FastDFSClient.UploadFileAsync(storageNode, numArray, "jpg"); Console.WriteLine(storageLink + str); await FastDFSClient.RemoveFileAsync(group, str); Console.WriteLine("FastDFSClient.RemoveFile" + str); } }
public Task DeleteFileAsync(string fileUrl, CancellationToken token) { return(FastDFSClient.RemoveFileAsync(fileUrl, token)); }