[][src]Struct multer::Multipart

pub struct Multipart { /* fields omitted */ }

Represents the implementation of multipart/form-data formatted data.

This will parse the source stream into Field instances via its Stream implementation.

To maintain consistency in the underlying stream, this will not yield more than one Field at a time. A Drop implementation on Field is used to signal when it's time to move forward, so do avoid leaking that type or anything which contains it.

The Fields can be accessed via the Stream API or the methods defined in this type.

Examples

use multer::Multipart;
use bytes::Bytes;
use std::convert::Infallible;
use futures::stream::once;

let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
let stream = once(async move { Result::<Bytes, Infallible>::Ok(Bytes::from(data)) });
let mut multipart = Multipart::new(stream, "X-BOUNDARY");

while let Some(field) = multipart.next_field().await.unwrap() {
    println!("Field: {:?}", field.text().await)
}

Implementations

impl Multipart[src]

pub fn new<S, O, E, B>(stream: S, boundary: B) -> Multipart where
    S: Stream<Item = Result<O, E>> + Send + 'static,
    O: Into<Bytes> + 'static,
    E: Into<Box<dyn Error + Send + Sync>> + 'static,
    B: Into<String>, 
[src]

Construct a new Multipart instance with the given Bytes stream and the boundary.

pub fn new_with_constraints<S, O, E, B>(
    stream: S,
    boundary: B,
    constraints: Constraints
) -> Multipart where
    S: Stream<Item = Result<O, E>> + Send + 'static,
    O: Into<Bytes> + 'static,
    E: Into<Box<dyn Error + Send + Sync>> + 'static,
    B: Into<String>, 
[src]

Construct a new Multipart instance with the given Bytes stream and the boundary.

pub fn with_reader<R, B>(reader: R, boundary: B) -> Multipart where
    R: AsyncRead + Send + 'static,
    B: Into<String>, 
[src]

Construct a new Multipart instance with the given AsyncRead reader and the boundary.

Optional

This requires the optional reader feature to be enabled.

Examples

use multer::Multipart;
use bytes::Bytes;
use std::convert::Infallible;
use futures::stream::once;

let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
let reader = data.as_bytes();
let mut multipart = Multipart::with_reader(reader, "X-BOUNDARY");

while let Some(mut field) = multipart.next_field().await.unwrap() {
    while let Some(chunk) = field.chunk().await.unwrap() {
        println!("Chunk: {:?}", chunk);
    }
}

pub fn with_reader_with_constraints<R, B>(
    reader: R,
    boundary: B,
    constraints: Constraints
) -> Multipart where
    R: AsyncRead + Send + 'static,
    B: Into<String>, 
[src]

Construct a new Multipart instance with the given AsyncRead reader and the boundary.

Optional

This requires the optional reader feature to be enabled.

Examples

use multer::Multipart;
use bytes::Bytes;
use std::convert::Infallible;
use futures::stream::once;

let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
let reader = data.as_bytes();
let mut multipart = Multipart::with_reader(reader, "X-BOUNDARY");

while let Some(mut field) = multipart.next_field().await.unwrap() {
    while let Some(chunk) = field.chunk().await.unwrap() {
        println!("Chunk: {:?}", chunk);
    }
}

pub async fn next_field<'_>(&'_ mut self) -> Result<Option<Field>>[src]

Yields the next Field if available.

For more info, go to Field.

pub async fn next_field_with_idx<'_>(
    &'_ mut self
) -> Result<Option<(usize, Field)>>
[src]

Yields the next Field with their positioning index as a tuple (usize, Field).

For more info, go to Field.

Examples

use multer::Multipart;
use bytes::Bytes;
use std::convert::Infallible;
use futures::stream::once;

let data = "--X-BOUNDARY\r\nContent-Disposition: form-data; name=\"my_text_field\"\r\n\r\nabcd\r\n--X-BOUNDARY--\r\n";
let reader = data.as_bytes();
let mut multipart = Multipart::with_reader(reader, "X-BOUNDARY");

while let Some((idx, field)) = multipart.next_field_with_idx().await.unwrap() {
    println!("Index: {:?}, Content: {:?}", idx, field.text().await)
}

Trait Implementations

impl Stream for Multipart[src]

type Item = Result<Field, Error>

Values yielded by the stream.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<St> StreamExt for St where
    St: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized
[src]