public IActionResult GetFile([FromServices] VirgoFileProvider fp, string id, string csName = null) { var file = fp.GetFile(id, true, KnifeVirgo.ConfigInfo.CreateDC(csName)); if (file == null) { return(BadRequest(Localizer["FileNotFound"])); } file.DataStream?.CopyToAsync(Response.Body); file.DataStream.Dispose(); return(new EmptyResult()); }
public IActionResult DownloadFile([FromServices] VirgoFileProvider fp, string id, string csName = null) { var file = fp.GetFile(id, true, KnifeVirgo.ConfigInfo.CreateDC(csName)); if (file == null) { return(BadRequest(Localizer["FileNotFound"])); } var ext = file.FileExt.ToLower(); var contenttype = "application/octet-stream"; if (ext == "pdf") { contenttype = "application/pdf"; } if (ext == "png" || ext == "bmp" || ext == "gif" || ext == "tif" || ext == "jpg" || ext == "jpeg") { contenttype = $"image/{ext}"; } return(File(file.DataStream, contenttype, file.FileName ?? (Guid.NewGuid().ToString() + ext))); }