gpt4 book ai didi

c# - 从文件系统返回图像

转载 作者:行者123 更新时间:2023-11-30 19:55:06 26 4
gpt4 key购买 nike

文件系统中有成功上传的图片,我想访问它。所以,我写了GET-method

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

我完全确定在所需路径中有所需名称的文件,但任何时候尝试创建 File(path, "image/jpeg") 我得到 Could no查找文件 异常。似乎我无法访问 wwwroot 之外的文件夹。也许我错过了来自 working with static file article 的重要内容?

那么,谁能解释一下如何通过 GET-method 返回存储在 web-server 文件夹外的文件系统中的图像

最佳答案

虽然@Shyju 所说的是正确的并且File 辅助方法不接受物理文件路径,但PhysicalFile 辅助方法可以(参见GitHub source)。

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

关于c# - 从文件系统返回图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39310248/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com