Skip to main content
 首页 » 编程设计

c#之.net webapi 文件路径作为参数

2024年02月01日24freeliver54

我想知道是否有可能以某种方式将相对 filepath 作为字符串发送到 GET 方法。

我的方法:

public HttpResponseMessage Get([FromUri] string fileName) 
 
My route: 
    config.Routes.MapHttpRoute( 
    name: "MiscApiDownload", 
    routeTemplate: "api/{controller}/download/{fileName}", 
    defaults: new {action = "Download" } 
); 

像 "test.jpg" 这样的文件名可以工作,但是只要我有一个 subdir exp。 "folder/test.jpg" 找不到该方法了。这是合乎逻辑的。问题是在 URI 中是否有执行此操作的好方法。我不想在体内接收它。

请您参考如下方法:

使用一个包罗万象的参数

"api/{controller}/download/{*fileName}"