file upload and multipart issue #2739
-
| Version Platform Description 
 Experiments with issue #1901I did add snippet as below: // ... same code as issue comment https://github.com/hyperium/hyper/issues/1901#issuecomment-521875065
async fn service(req: Request<Body>) -> Result<(), Infallible> {
    match body_multipart(req).await {
        Ok(body) => Ok(()),
        Err(e) => {
            let message = format!("Error: {}", e.to_string());
            debug!("{}", message);
            Ok(())
        }
    }
}
#[tokio::main]
pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    initiate_logging();
    info!("info -> Welcome to Bulk services.");
    let address: SocketAddr = ([127, 0, 0, 1], 3000).into();
    debug!("F:main -> address: {:?}", address);
    // For every connection, we must make a `Service` to handle all
    // incoming HTTP requests on said connection.
    let make_svc = make_service_fn(|_conn| {
        // This is the `Service` that will handle the connection.
        // `service_fn` is a helper to convert a function that
        // returns a Response into a `Service`.
        async { Ok::<_, Infallible>(service_fn(service)) }
    });
    let server = Server::bind(&address).serve(make_svc);
    debug!("Listening on http://{}", address);
    server.await?;
    Ok(())
}
fn initiate_logging() {
    dotenv().ok();
    if std::env::var("PWD").is_err() {
        std::env::set_var("PWD", env!("CARGO_MANIFEST_DIR"));
    }
    std::env::set_var("RUST_LOG", "debug, actix_web=debug");
    env_logger::init();
}But I found below errors: error[E0271]: type mismatch resolving `<impl futures_util::Future as futures_util::Future>::Output == Result<hyper::Response<_>, _>`
   --> src\main.rs:129:41
    |
129 |     let server = Server::bind(&address).serve(make_svc);
    |                                         ^^^^^ expected `()`, found struct `hyper::Response`
    |
    = note: expected enum `Result<(), Infallible>`
               found enum `Result<hyper::Response<_>, _>`
    = note: required because of the requirements on the impl of `hyper::service::Service<hyper::Request<hyper::Body>>` for `hyper::service::util::ServiceFn<fn(hyper::Request<hyper::Body>) -> impl futures_util::Future {service}, hyper::Body>`
    = note: required because of the requirements on the impl of `hyper::service::http::HttpService<hyper::Body>` for `hyper::service::util::ServiceFn<fn(hyper::Request<hyper::Body>) -> impl futures_util::Future {service}, hyper::Body>`
error[E0277]: the trait bound `hyper::common::exec::Exec: hyper::common::exec::ConnStreamExec<impl futures_util::Future, _>` is not satisfied
   --> src\main.rs:133:5
    |
133 |     server.await?;
    |     ^^^^^^^^^^^^ the trait `hyper::common::exec::ConnStreamExec<impl futures_util::Future, _>` is not implemented for `hyper::common::exec::Exec`
    |
    = help: the following implementations were found:
              <hyper::common::exec::Exec as hyper::common::exec::ConnStreamExec<F, B>>
    = note: required because of the requirements on the impl of `futures_util::Future` for `hyper::server::conn::spawn_all::NewSvcTask<AddrStream, impl futures_util::Future, hyper::service::util::ServiceFn<fn(hyper::Request<hyper::Body>) -> impl futures_util::Future {service}, hyper::Body>, hyper::common::exec::Exec, hyper::server::conn::spawn_all::NoopWatcher>`
    = note: required because of the requirements on the impl of `hyper::common::exec::NewSvcExec<AddrStream, impl futures_util::Future, hyper::service::util::ServiceFn<fn(hyper::Request<hyper::Body>) -> impl futures_util::Future {service}, hyper::Body>, hyper::common::exec::Exec, hyper::server::conn::spawn_all::NoopWatcher>` for `hyper::common::exec::Exec`
    = note: 1 redundant requirement hidden
    = note: required because of the requirements on the impl of `futures_util::Future` for `hyper::Server<AddrIncoming, hyper::service::make::MakeServiceFn<[closure@src\main.rs:122:36: 127:6]>>`
note: required by `futures_util::Future::poll`
error[E0271]: type mismatch resolving `<impl futures_util::Future as futures_util::Future>::Output == Result<hyper::Response<_>, _>`
   --> src\main.rs:133:5
    |
133 |     server.await?;
    |     ^^^^^^^^^^^^ expected struct `hyper::Response`, found `()`
    |
    = note: expected enum `Result<hyper::Response<_>, _>`
               found enum `Result<(), Infallible>`
    = note: required because of the requirements on the impl of `futures_util::Future` for `hyper::proto::h2::server::H2Stream<impl futures_util::Future, _>`
    = note: required because of the requirements on the impl of `hyper::common::exec::ConnStreamExec<impl futures_util::Future, _>` for `hyper::common::exec::Exec`
    = note: 1 redundant requirement hidden
    = note: required because of the requirements on the impl of `futures_util::Future` for `hyper::Server<AddrIncoming, hyper::service::make::MakeServiceFn<[closure@src\main.rs:122:36: 127:6]>>`
note: required by `futures_util::Future::poll`
Some errors have detailed explanations: E0271, E0277.
For more information about an error, try `rustc --explain E0271`.
warning: `faas_poc` (bin "faas_poc") generated 2 warnings
error: could not compile `faas_poc` due to 3 previous errors; 2 warnings emitted
 | 
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
| Your service function needs to return a  async fn service(req: Request<Body>) -> Result<Response<Body>, Infallible> {
    // ...
}For multipart, there are a lot of options. I can't say which one you definitely should use, but multer seems like a comprehensive library. | 
Beta Was this translation helpful? Give feedback.
-
| @seanmonstar again very thankful which you did save alot of effort for me. I did implement  Till now the difference between implementing  Implementing  pub struct FieldEntry {
    field: actix_multipart::Field,
}
impl AsyncRead for FieldEntry {
    fn poll_read(
        mut self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut ReadBuf<'_>,
    ) -> Poll<std::io::Result<()>> {
        // ...
    }
}Implementing  pub struct FieldEntry<'r> {
    field: &'r mut multer::Field<'static>,
}
impl<'r> AsyncRead for FieldEntry<'r> {
    fn poll_read(
        mut self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut ReadBuf<'_>,
    ) -> Poll<std::io::Result<()>> {
        // ...
    }
} | 
Beta Was this translation helpful? Give feedback.
Your service function needs to return a
Response, not a(). Switch to a signature like this:For multipart, there are a lot of options. I can't say which one you definitely should use, but multer seems like a comprehensive library.