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); }
public void FastDfsOperation(string groupName, string filePath, string fileExt) { var storageNode = _client.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)); }