You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Leptos框架下多部分文件上传的实现困惑与求助

Leptos框架下多部分文件上传的实现困惑与求助

我最近在Leptos框架里搞多部分文件上传,卡了好半天没弄明白怎么正确实现。

目前我写的代码是这样的:

前端处理部分

let on_file_input = move |ev| {
    log!("file input");

    spawn_local(async move {
        let _ = upload(event_target_value(&ev)).await;
    });
};

view! {
    <input type="file"
        on:input=on_file_input
    />
}

后端服务器函数

#[server(Upload, "/api", "Cbor")]
pub async fn upload(file: String) -> Result<(), ServerFnError> {
    info!("got a file: {file}");

    Ok(())
}

现在这段代码看似能运行,我能拿到浏览器返回的伪路径(fakepath),但完全拿不到文件的实际内容。

我翻遍了Leptos的官方文档,也没找到相关的示例,但我觉得这事肯定是能实现的对吧?有没有大佬能给我指点一下方向?

备注:内容来源于stack exchange,提问作者munHunger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 08:32:58