Expand description

Actix Form Data

A library for retrieving form data from Actix Web’s multipart streams. It can stream uploaded files onto the filesystem (its main purpose), but it can also parse associated form data.

Example

 use actix_form_data::{Error, Field, Form, Value};
 use actix_web::{
     web::{post, resource},
     App, HttpResponse, HttpServer,
 };
 use futures_util::stream::StreamExt;

 async fn upload(uploaded_content: Value<()>) -> HttpResponse {
     println!("Uploaded Content: {:#?}", uploaded_content);
     HttpResponse::Created().finish()
 }

 #[actix_rt::main]
 async fn main() -> Result<(), anyhow::Error> {
     let form = Form::new()
         .field("Hey", Field::text())
         .field(
             "Hi",
             Field::map()
                 .field("One", Field::int())
                 .field("Two", Field::float())
                 .finalize(),
         )
         .field(
             "files",
             Field::array(Field::file(|_, _, mut stream| async move {
                 while let Some(_) = stream.next().await {
                     // do something
                 }
                 Ok(()) as Result<(), Error>
             })),
         );

     println!("{:?}", form);

     HttpServer::new(move || {
         App::new()
             .wrap(form.clone())
             .service(resource("/upload").route(post().to(upload)))
     })
     .bind("127.0.0.1:8082")?;
     // commented out to prevent infinite doctest
     // .run()
     // .await?;

     Ok(())
 }

Structs

A structure that defines the fields expected in form data

Enums

The field type represents a field in the form-data that is allowed to be parsed.

The result of a succesfull parse through a given multipart stream.

Functions

Handle multipart streams from Actix Web