gpt4 book ai didi

rust - 使用 Iron Params 访问表单上传的文件路径

转载 作者:行者123 更新时间:2023-11-29 08:16:41 25 4
gpt4 key购买 nike

我尝试使用 Iron params 获取上传文件的临时路径.我有这个请求处理程序:

fn handler(req: &mut Request) -> IronResult<Response> {
let tmp_file_name = req.get_ref::<Params>().unwrap().find(&["file"]).unwrap();
println!("{:?}", tmp_file_name);
Ok( Response::with( (status::Ok, "Lorem Ipsum.") ) )
}

显示如下:

File { path: "/xxx/yyy", filename: Some("file.txt"), size: 123 }

但是如果我尝试访问路径:

println!("{:?}", tmp_file_name.path());

它不编译:

error: attempted access of field `path` on type `&params::Value`, 
but no field with that name was found

我想我错过了一些关于类型的基础知识,但我不知道从哪里(重新)开始。

最佳答案

params::Value不是 params::File ,而是一个枚举 could contain一个params::File .

这应该适用于适当的导入(未经测试):

match req.get_ref::<Params>().unwrap().find(&["file"]) {
Some(&Value::File(ref file)) => {
println!("{:?}", file.path())
}
_ => {
println!("no file");
}
}

关于rust - 使用 Iron Params 访问表单上传的文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38348365/

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