// Pobiera plik z zakupionym ebookiem. public ContentResult <DownloadFileDto> DownloadMyEbookById(string username, int id) { var ebook = context.Files .Include(x => x.User) .Where(x => x.User.Name == username) .SingleOrDefault(x => x.Id == id); if (ebook == null) { return(new ContentResult <DownloadFileDto> { Content = null }); } var ebookName = ebook.Name.Split('/').Last(); var dto = new DownloadFileDto { Name = ebookName, Type = ebookName == "pdf" ? "application/pdf" : "application/epub+zip" }; return(new ContentResult <DownloadFileDto> { Content = dto }); }
// Pobiera plik ebooka znajdujący się na serwerze strony. public ContentResult <DownloadFileDto> DownloadFileById(int id) { var ebook = context.Files .SingleOrDefault(x => x.Id == id); if (ebook == null) { return(new ContentResult <DownloadFileDto> { Content = null }); } var ebookName = ebook.Name.Split('/').Last(); var dto = new DownloadFileDto { Name = ebookName, Type = ebookName == "pdf" ? "application/pdf" : "application/epub+zip" }; return(new ContentResult <DownloadFileDto> { Content = dto }); }
public Either <IError, DownloadFileDto> DownloadFile(string token, StringDto fileName) { Message <BucketMessage> message = new Message <BucketMessage>("bucket/getFile") { Data = new BucketMessage() { Token = token, Path = fileName.Path + "/" + fileName.Value } }; NetMQMessage response = RequestSocketFactory.SendRequest(message.ToNetMQMessage()); string responseTopic = response.First.ConvertToString(); if (responseTopic.Equals("Response")) { Message <BucketMessage> successMessage = new Message <BucketMessage>(response); byte[] data = successMessage.Bytes.ToByteArray(); DownloadFileDto upload = new DownloadFileDto(); upload.File = data; upload.Value = fileName.Value; upload.Type = GetContentType(fileName.Value); return(new Right <IError, DownloadFileDto>(upload)); } return(new Left <IError, DownloadFileDto>(GetError(response))); }
public async Task <DownloadFileDto> DownloadFile(string fileId) { DriveService service; try { service = AuthorizationService.ServiceAccountAuthorization(); } catch (Exception e) { throw e; } var request = service.Files.Get(fileId); Google.Apis.Drive.v3.Data.File file = service.Files.Get(fileId).Execute(); var stream = new System.IO.MemoryStream(); await request.DownloadAsync(stream); stream.Seek(0, SeekOrigin.Begin); DownloadFileDto dto = new DownloadFileDto() { Name = file.Name, Type = file.MimeType, Content = stream }; return(dto); }
public string GetFileType(DownloadFileDto model) { var filePath = model.FilePath + model.FileName; var fileInfo = new FileInfo(filePath); var result = "application" + fileInfo.Extension.Replace(".", "/"); return(result); }
public async Task <ServiceResponse <DownloadFileDto> > DownloadFile(string file, int id) { ServiceResponse <DownloadFileDto> response = new ServiceResponse <DownloadFileDto>(); var data = new DownloadFileDto(); data.PathRoot = Path.Combine(_pathRoot, id.ToString()); var pengajuan = await _context.Tb_pengajuan.FirstOrDefaultAsync(c => c.Id == id); if (pengajuan == null) { response.Status = false; response.Message = "Data Pengajuan tidak ditemukan"; return(response); } var stat = false; foreach (var item in pengajuan.GetType().GetProperties()) { if (item.Name.ToLower() == file.ToLower()) { var name = item.GetValue(pengajuan, null); data.FileName = (name == null ? "" : name.ToString()); stat = true; } if (stat) { break; } } if (data.FileName == null) { response.Status = false; response.Message = "Jenis File tidak sesuai / File tidak ditemukan"; return(response); } var path = Path.Combine(data.PathRoot, data.FileName); if (!File.Exists(path)) { response.Status = false; response.Message = "Jenis File tidak sesuai / File tidak ditemukan"; } response.Data = data; return(response); }
public async Task <FileStreamResult> Download(Guid fileId) { DownloadFileDto file = await _mediator.Send(new DownloadFileRequest(fileId)); var stream = await file.StreamAccessor(); var result = new FileStreamResult(stream, file.ContentType); var disposition = new ContentDisposition { Inline = true, // Because can't escape 2 spaces in name with russian symbols FileName = Uri.EscapeDataString(file.FileName), Size = stream.Length, }; _httpContextAccessor.HttpContext.Response.Headers.Add( HeaderNames.ContentDisposition, disposition.ToString()); return(result); }