Struct ipfs_api::Form[]

pub struct Form<'a> { /* fields omitted */ }
Expand description

Implements the multipart/form-data media type as described by RFC 7578.

See.

Implementations

Creates a new form with the specified boundary generator function.

Examples
struct TestGenerator;

impl BoundaryGenerator for TestGenerator {
    fn generate_boundary() -> String {
        "test".to_string()
    }
}

let form = multipart::Form::new::<TestGenerator>();

Adds a text part to the Form.

Examples
use common_multipart_rfc7578::client::multipart;

let mut form = multipart::Form::default();

form.add_text("text", "Hello World!");
form.add_text("more", String::from("Hello Universe!"));

Adds a readable part to the Form.

Examples
use common_multipart_rfc7578::client::multipart;
use std::io::Cursor;

let bytes = Cursor::new("Hello World!");
let mut form = multipart::Form::default();

form.add_reader("input", bytes);

Adds a file, and attempts to derive the mime type.

Examples
use common_multipart_rfc7578::client::multipart;

let mut form = multipart::Form::default();

form.add_file("file", file!()).expect("file to exist");

Adds a readable part to the Form as a file.

Examples
use common_multipart_rfc7578::client::multipart;
use std::io::Cursor;

let bytes = Cursor::new("Hello World!");
let mut form = multipart::Form::default();

form.add_reader_file("input", bytes, "filename.txt");

Adds a readable part to the Form as a file with a specified mime.

Examples
use common_multipart_rfc7578::client::multipart;
use std::io::Cursor;

let bytes = Cursor::new("Hello World!");
let mut form = multipart::Form::default();

form.add_reader_file_with_mime("input", bytes, "filename.txt", mime::TEXT_PLAIN);

Adds a file with the specified mime type to the form. If the mime type isn’t specified, a mime type will try to be derived.

Examples
use common_multipart_rfc7578::client::multipart;

let mut form = multipart::Form::default();

form.add_file_with_mime("data", "test.csv", mime::TEXT_CSV);

Updates a request instance with the multipart Content-Type header and the payload data.

Examples
use hyper::{Method, Request};
use hyper_multipart_rfc7578::client::multipart;

let mut req_builder = Request::post("http://localhost:80/upload");
let mut form = multipart::Form::default();

form.add_text("text", "Hello World!");
let req = form.set_body::<multipart::Body>(req_builder).unwrap();

Updates a request instance with the multipart Content-Type header and the payload data.

Allows converting body into an intermediate type.

Examples
use hyper::{Body, Method, Request};
use hyper_multipart_rfc7578::client::multipart;

let mut req_builder = Request::post("http://localhost:80/upload");
let mut form = multipart::Form::default();

form.add_text("text", "Hello World!");
let req = form.set_body_convert::<hyper::Body, multipart::Body>(req_builder).unwrap();

Trait Implementations

Creates a new form with the default boundary generator.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more