Skip to content

Commit 939fc43

Browse files
committed
Fix Entry::from_file
1 parent a03ac12 commit 939fc43

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/multipart/entry.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::{bail, Body, Mime};
1+
use crate::{Body, Mime};
22

33
use std::fmt::{self, Debug};
4+
use std::path::Path;
45

56
/// A single multipart entry.
67
///
@@ -21,24 +22,16 @@ impl Entry {
2122

2223
/// Create an empty `Entry`.
2324
pub fn empty(name: impl AsRef<str>) -> Self {
24-
Self {
25-
name: name.as_ref().to_owned(),
26-
body: Body::empty(),
27-
}
25+
Self::new(name, Body::empty())
2826
}
2927

3028
/// Create an `Entry` from a file.
31-
///
3229
#[cfg(all(feature = "async_std", not(target_os = "unknown")))]
33-
pub async fn from_file<P>(path: P) -> crate::Result<Self>
30+
pub async fn from_file<S, P>(name: S, path: P) -> crate::Result<Self>
3431
where
35-
P: AsRef<std::path::Path>,
32+
S: AsRef<str>,
33+
P: AsRef<Path>,
3634
{
37-
let path = path.as_ref();
38-
let name = match path.to_str() {
39-
Some(p) => p.to_owned(),
40-
None => bail!("Could not convert file name to unicode"),
41-
};
4235
let body = Body::from_file(path).await?;
4336
Ok(Self::new(name, body))
4437
}

0 commit comments

Comments
 (0)