1
0
mirror of https://github.com/actix/examples synced 2025-02-17 07:23:29 +01:00

Fixed possible panic in multipart example (#276)

* Fixed possible panic

* Fixed possible panic in multipart-async-std
This commit is contained in:
Voldracarno Draconor 2020-03-22 00:31:45 +01:00 committed by GitHub
parent 7eaa87f4f1
commit 5320117bca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View File

@ -1,12 +1,11 @@
use actix_multipart::Multipart;
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
use async_std::prelude::*;
use futures::StreamExt;
use futures::{StreamExt, TryStreamExt};
async fn save_file(mut payload: Multipart) -> Result<HttpResponse, Error> {
// iterate over multipart stream
while let Some(item) = payload.next().await {
let mut field = item?;
while let Ok(Some(mut field)) = payload.try_next().await {
let content_type = field
.content_disposition()
.ok_or_else(|| actix_web::error::ParseError::Incomplete)?;

View File

@ -2,12 +2,11 @@ use std::io::Write;
use actix_multipart::Multipart;
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
use futures::StreamExt;
use futures::{StreamExt, TryStreamExt};
async fn save_file(mut payload: Multipart) -> Result<HttpResponse, Error> {
// iterate over multipart stream
while let Some(item) = payload.next().await {
let mut field = item?;
while let Ok(Some(mut field)) = payload.try_next().await {
let content_type = field.content_disposition().unwrap();
let filename = content_type.get_filename().unwrap();
let filepath = format!("./tmp/{}", filename);