axum multipart/form-dataを受け取る
multipart/form-data を特定のstructにマップできる
code:_.rs
struct CreateUserRequest {
first_name: String,
last_name: String,
}
async fn create_user(data: TypedMultipart<CreateUserRequest>) -> StatusCode {
println!("name: '{} {}'", data.first_name, data.last_name); // Your logic here.
StatusCode::CREATED
}
ファイルアップロードは tempfile::NamedTempFile で受け取り可能 code:_.rs
struct UploadAssetRequest {
// The unlimited arguments means that this field will be limited to the
// total size of the request body. If you want to limit the size of this
// field to a specific value you can also specify a limit in bytes, like
// '5MiB' or '1GiB'.
image: FieldData<NamedTempFile>,
// This field will be limited to the default size of 1MiB.
author: String,
}