dotnet core api 訪問在線文件 出現(xiàn) :Timeouts are not supported on this stream.
- 故障代碼
[HttpGet("GetMusicUrl")]
public IActionResult GetMusicUrl([FromQuery] int id)
{
// 示例:根據(jù) id 獲取實際文件路徑
var filePath = $"D:/AdownLoad/huadian.mp3";
if (!System.IO.File.Exists(filePath))
{
return NotFound("文件不存在");
}
var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
return File(stream, "audio/mpeg", enableRangeProcessing: true); // 支持音頻拖動播放
}
- 正常代碼
[HttpGet("GetMusicUrl")]
public IResult GetMusicUrl([FromQuery] int id) // 這里把 IActionResult 換成了IResult 就好了
{
// 示例:根據(jù) id 獲取實際文件路徑
var filePath = $"D:/AdownLoad/huadian.mp3";
if (!System.IO.File.Exists(filePath))
{
throw new Exception("文件不存在");
}
var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
return Results.File(stream, "audio/mpeg");
}
這問題 問了半天AI 都不知道,困難了一下午 還好解決了
可能是這兩個類有什么使用的注意點 我對這塊不太了解 知道的可以回答一下
浙公網(wǎng)安備 33010602011771號