我需要在我的操作方法中返回一个 FileContentResult,这可能有很多东西。 pdf、图像、Excel 电子表格等...
我如何确定要返回的内容类型以及客户端(浏览器)上的内容将检查/使用该内容/MIME 类型?如果除了 javascript 之外什么都没有,那么正确的 MIME/内容类型有多重要。
MIME 和内容类型是同一件事,对吗?
public IActionResult Download(string documentName,string filename){
string filePath = path.Combine(Directory.GetCurrentDirectory(),"Uploads",$"{documentName}_{fileName}")
byte[] fileContents = System.IO.File.ReadAllBytes(filePath);
return File(fileContents,"What goes here?");
尝试这样的事情:
var provider = new FileExtensionContentTypeProvider();
if (!provider.TryGetContentType(originalImagePath, out var contentType))
{
contentType = "application/octet-stream";
}