January 2019
Intermediate to advanced
520 pages
14h 32m
English
upload_handler is a bit complex, because it takes POST requests with a form that contains the uploaded image:
fn upload_handler(req: HttpRequest<State>) -> impl Future<Item = HttpResponse, Error = WebError> { req.multipart() .map(handle_multipart_item) .flatten() .into_future() .and_then(|(bytes, stream)| { if let Some(bytes) = bytes { Ok(bytes) } else { Err((MultipartError::Incomplete, stream)) } }) .map_err(|(err, _)| WebError::from(err)) .and_then(move |image| { debug!("Image: {:?}", image); let request = QrRequest { image }; req.state() .addr .send(SendMessage(request)) .from_err() .map(move |task_id| { let record = Record { task_id: task_id.clone(), timestamp: Utc::now(), status: Status::InProgress, }; req.state().tasks.lock().unwrap().insert(task_id, ...Read now
Unlock full access