public async Task <IActionResult> Download([FromQuery] int AttachmentID) { //جلب الملف من السيرفر upload var result = _attachmentRepository.Find(p => p.AttachmentID == AttachmentID); if (result != null) { if (_appSettings.UploadFileToDataBase == "0") { var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "Upload"); var filePath = Path.Combine(uploads, result.FileName); if (!System.IO.File.Exists(filePath)) { return(NotFound()); } var memory = new MemoryStream(); using (var stream = new FileStream(filePath, FileMode.Open)) { await stream.CopyToAsync(memory); } memory.Position = 0; return(File(memory, GetContentType(filePath), result.FileName)); } else { Stream stream2 = new MemoryStream(result.FileContent); return(File(stream2, result.FileType, result.FileName)); // result.FileType); } } else { return(NotFound()); } }
public Attachment Find(long id) { return(_attachmentRepository.Find(x => x.Id == id)); }