public UploadResult Upload(UploadConfig config) { if (string.IsNullOrEmpty(config.PreviosName)) { var fileName = string.Empty; var storageNode = _client.GetStorageNode(config.GroupName); if (!config.Chunked) { fileName = _client.UploadFile(storageNode, config.Buffer, Path.GetExtension(config.FileName)); } else { //分段上传需要调用这个方法 fileName = _client.UploadAppenderFile(storageNode, config.Buffer, Path.GetExtension(config.FileName)); } return(new UploadResult { FilePath = fileName, OriginalName = config.FileName }); } else { //分段上传:需要提供上传GroupName, 文件上传地址PreviosName,文件上传内容filebody //续传 地址config.PreviosName _client.AppendFile(config.GroupName, config.PreviosName, config.Buffer); return(new UploadResult { FilePath = config.PreviosName, OriginalName = config.FileName }); } }
public void FastDfsOperation(string groupName, string filePath, string fileExt) { var storageNode = FastDfsClient.GetStorageNode(groupName); var uploadFile = File.ReadAllBytes(filePath); var fileName = _client.UploadFile(storageNode, uploadFile, fileExt); var downloadFile = _client.DownloadFile(storageNode, fileName); _client.RemoveFile(groupName, fileName); Assert.Equal(Md5Helper.Get32Md5(uploadFile), Md5Helper.Get32Md5(downloadFile)); }
public string UploadFile(byte[] data, string fileExt) { if (client == null) { Lib.Log.WriteOperationLog("client null"); } if (storageNode == null) { Lib.Log.WriteOperationLog("storageNode null"); } if (data == null) { Lib.Log.WriteOperationLog("data null"); } if (fileExt == null) { Lib.Log.WriteOperationLog("fileExt null"); } var fileKey = client.UploadFile(storageNode, data, fileExt); return(fileKey); }
public string UploadFile(byte[] fileBytes, string fileName) { var strArr = fileName.Split('.'); if (strArr.Length < 2) throw new ArgumentException(nameof(fileName)); var fileNameBuilder = new StringBuilder(); for (var i = 0; i < strArr.Length - 1; i++) fileNameBuilder.Append(strArr[i]); var file = fileNameBuilder.ToString(); var fileExt = strArr.Last(); if (string.IsNullOrWhiteSpace(file) || string.IsNullOrWhiteSpace(fileExt)) throw new ArgumentException(nameof(fileName)); var storageNode = _fastDfsClient.GetStorageNode(_groupName); var fileDfsInfo = new FileDfsInfo { Id = Guid.NewGuid(), DfsFileName = _fastDfsClient.UploadFile(storageNode, fileBytes, fileExt), FileName = fileName, UtcCreateTime = DateTime.Now }; _repository?.Add(fileDfsInfo); return fileDfsInfo.DfsFileName; }