/// <summary> /// 获取文件信息 /// </summary> /// <param name="storageNode">GetStorageNode方法返回的存储节点</param> /// <param name="fileId">文件名</param> /// <param name="clusterName">集群名称</param> /// <returns></returns> public async ValueTask <FastDFSFileInfo> GetFileInfo(StorageNode storageNode, string fileId, string clusterName = "") { var request = new QueryFileInfo(storageNode.GroupName, fileId); var response = await _executer.Execute(request, clusterName, storageNode.ConnectionAddress); return(new FastDFSFileInfo(response.FileSize, response.CreateTime, response.Crc32)); }
public async Task <FileResult> DownloadFileAsync(Guid fileId) { FileResult fileResult = null; double maxFileSize = 1932735283;//1.8GB try { logger.Info($"Begin search file by id:{fileId.ToString()}]"); QueryFileInfo queryInfo = new QueryFileInfo(); queryInfo.FileIds = new List <Guid>(); queryInfo.FileIds.Add(fileId); SearchResults result = await SearchFileInfoById(fileId); UploadFileResponseInfo fileInfo; if (result.Data.Count > 0) { fileInfo = result.Data.FirstOrDefault(); logger.Info($"search file info: fileId{fileInfo.FileId}],filename:[{fileInfo.FileName}],filesize:[{fileInfo.FileSize}]"); if (fileInfo.FileSize < maxFileSize) { logger.Info($"Go to default download, fileId:{fileInfo.FileId}]"); fileResult = await DownloadFile(fileId); } else { logger.Info($"Go to HttpWebRequest download, fileId:{fileInfo.FileId}]"); fileResult = HttpWebDownFile(fileInfo); } } else { logger.Info($"No file was found, fileId:{fileId}]"); } } catch (Exception e) { logger.Error(string.Format("An error occurred while download file with file id : '{0}'. error : {1}.", fileId, e.ToString())); } return(fileResult); }