public IActionResult Part([FromForm] UploadPart model) { if (model.files.Length > 0 && model.files.Length == Convert.ToInt32(Assistant.getHeaderValue(Request, "PartSize"))) { var webRootPath = _environment.WebRootPath; var uploadTempPath = Path.Combine(webRootPath, "Temp", Convert.ToString(Assistant.getHeaderValue(Request, "UploadId"))); if (Directory.Exists(uploadTempPath)) { var chankPath = Path.Combine(uploadTempPath, Convert.ToString(Assistant.getHeaderValue(Request, "SequenceNumber")) + ".bmp"); using (FileStream fileStream = new FileStream(chankPath, FileMode.OpenOrCreate)) { model.files.CopyTo(fileStream); fileStream.Flush(); return(Ok(new Response() { IsSuccess = true, Message = "پارت مورد نظر با موفقیت آپلود شد", Data = Assistant.getHeaderValue(Request, "SequenceNumber") })); } } else { return(NotFound()); } } else { return(BadRequest("محتوایی جهت آپلود وجود ندارد")); } }
private IEnumerable <UploadPart> GenerateUploadParts(long totalSizeInBytes) { var sizeDistribution = DistributionStrategy.BySize(totalSizeInBytes, _settings.ChunkSizeInBytes); var parts = new UploadPart[sizeDistribution.Count]; var offset = 0L; for (var i = 0; i < parts.Length; i++) { parts[i] = new UploadPart { Id = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes($"{i:0000000}")), Offset = offset, SizeInBytes = sizeDistribution[i] }; offset += sizeDistribution[i]; } return(parts); }