我正在使用 rust actix 上传一些 zip 文件,现在我想检查上传的 zip 文件大小是否小于 100MB。这是代码:
async fn upload_full_proj(
MultipartForm(form): MultipartForm<FullProjUpload>,
login_user_info: LoginUserInfo,
) -> HttpResponse {
return save_full_proj(form, &login_user_info).await;
}
这是
FullProjUpload
定义如下:
use actix_multipart::form::{MultipartForm, tempfile::TempFile, text::Text};
#[derive(Debug, MultipartForm)]
pub struct FullProjUpload {
#[multipart(rename = "file")]
pub files: Vec<TempFile>,
pub project_id: Text<String>,
pub parent: Text<String>
}
我尝试像这样限制项目条目的大小:
#[actix_web::main]
async fn main() -> std::io::Result<()> {
rust_i18n::set_locale("zh-CN");
log4rs::init_file("log4rs.yaml", Default::default()).unwrap();
let port: u16 = get_app_config("texhub.port").parse().unwrap();
let address = ("0.0.0.0", port);
consume_sys_events();
HttpServer::new(|| {
App::new().app_data(
MultipartFormConfig::default()
.total_limit(1048576) // 1 MB = 1024 * 1024
.memory_limit(2097152) // 2 MB = 2 * 1024 * 1024
.error_handler(handle_multipart_error),
)
})
.workers(3)
.bind(address)?
.run()
.await
}
并且工作正常,但是如何限制每个 actix api 中的文件大小?因为图片上传大小限制(<2MB) is different with the project zip file size limit(<100MB). I also need to check the size without full received the file.