[HttpGet("filePreview")]
public async Task<IActionResult> GetFileForPreview(string filePath)
{
if (!System.IO.File.Exists(filePath))
{
return NotFound("File not found");
}
var extension = Path.GetExtension(filePath).ToLowerInvariant();
var mimeType = extension switch
{
".txt" => "text/plain",
".jpg" or ".jpeg" => "image/jpeg",
".png" => "image/png",
".gif" => "image/gif",
".mp4" => "video/mp4",
".webm" => "video/webm",
".mp3" => "audio/mpeg",
".wav" => "audio/wav",
".webp" => "image/webp",
".pdf" => "application/pdf",
_ => null
};
if (mimeType == null)
{
return BadRequest("Unsupported file type");
}
Response.Headers["X-Accel-Buffering"] = "no";
return PhysicalFile(filePath, mimeType, enableRangeProcessing: true);
}
[HttpGet("filePreview")]
public async Task<IActionResult> GetFileForPreview(string filePath)
{
if (!System.IO.File.Exists(filePath))
{
return NotFound("File not found");
}
var extension = Path.GetExtension(filePath).ToLowerInvariant();
var mimeType = extension switch
{
".txt" => "text/plain",
".jpg" or ".jpeg" => "image/jpeg",
".png" => "image/png",
".gif" => "image/gif",
".mp4" => "video/mp4",
".webm" => "video/webm",
".mp3" => "audio/mpeg",
".wav" => "audio/wav",
".webp" => "image/webp",
".pdf" => "application/pdf",
_ => null
};
if (mimeType == null)
{
return BadRequest("Unsupported file type");
}
Response.Headers["X-Accel-Buffering"] = "no";
return PhysicalFile(filePath, mimeType, enableRangeProcessing: true);
}