从文件系统返回图像

use*_*018 2 c# asp.net-core-mvc asp.net-core

在文件系统中成功上传了图像,我希望能够访问它.所以,我写了一些GET方法

[HttpGet]
public ActionResult Get(string id) {
    var path = $@"d:\smth\upload\{id}.jpeg";
    return File(path, "image/jpeg");
}
Run Code Online (Sandbox Code Playgroud)

我完全确定所需路径中的文件具有必需的名称,但无论何时尝试创建File(path, "image/jpeg")我都会获得Could no find file异常.好像我没有访问外面的文件夹wwwroot.也许我错过了使用静态文件文章的重要内容

那么,有没有人可以解释如何通过GET-method 返回存储在web-server文件夹外的文件系统中的图像

Tse*_*eng 6

虽然@Shyju说的是真的并且File辅助方法不接受物理文件路径,但PhysicalFile辅助方法确实如此(参见GitHub源代码).

[HttpGet]
public ActionResult Get(string id) {
    var path = $@"d:\smth\upload\{id}.jpeg";
    return PhysicalFile(path, "image/jpeg");
}
Run Code Online (Sandbox Code Playgroud)