mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-31 17:07:01 +02:00
fix: increase total limit in multipart example (#3567)
* fix: increase total limit in multipart example * update readme * Clarify where the limit comes from * Fix link --------- Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use actix_multipart::form::{json::Json as MpJson, tempfile::TempFile, MultipartForm};
|
||||
use actix_multipart::form::{
|
||||
json::Json as MpJson, tempfile::TempFile, MultipartForm, MultipartFormConfig,
|
||||
};
|
||||
use actix_web::{middleware::Logger, post, App, HttpServer, Responder};
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -9,6 +11,7 @@ struct Metadata {
|
||||
|
||||
#[derive(Debug, MultipartForm)]
|
||||
struct UploadForm {
|
||||
// Note: the form is also subject to the global limits configured using `MultipartFormConfig`.
|
||||
#[multipart(limit = "100MB")]
|
||||
file: TempFile,
|
||||
json: MpJson<Metadata>,
|
||||
@@ -28,9 +31,15 @@ async fn post_video(MultipartForm(form): MultipartForm<UploadForm>) -> impl Resp
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
HttpServer::new(move || App::new().service(post_video).wrap(Logger::default()))
|
||||
.workers(2)
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.service(post_video)
|
||||
.wrap(Logger::default())
|
||||
// Also increase the global total limit to 100MiB.
|
||||
.app_data(MultipartFormConfig::default().total_limit(100 * 1024 * 1024))
|
||||
})
|
||||
.workers(2)
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user