Skip to content

Commit e615895

Browse files
committed
Fix ci compile error?
1 parent e753038 commit e615895

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

patches/better_file_upload.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,32 @@
22
#[non_exhaustive]
33
pub enum File<'a> {
44
Path(::std::path::PathBuf),
5-
Buf{filename: ::std::borrow::Cow<'static, str>, file: reqwest::Body, length: Option<u64>, mime_type: ::std::borrow::Cow<'a, str>}
5+
Buf{filename: ::std::borrow::Cow<'static, str>, file: ::reqwest::Body, length: ::core::option::Option<u64>, mime_type: ::std::borrow::Cow<'a, str>}
66
}
77

88
impl File<'_> {
99
pub(crate) async fn get_multipart<T>(self) -> Result<::reqwest::multipart::Part, crate::apis::Error<T>> {
1010
match self {
11-
//The generator likes to generate this in 7.20.0. Why? Let's not?
12-
// let file = TokioFile::open(&p_form_file).await?;
13-
// let stream = FramedRead::new(file, BytesCodec::new());
14-
// let file_name = p_form_file
15-
// .file_name()
16-
// .map(|n| n.to_string_lossy().to_string())
17-
// .unwrap_or_default();
18-
// let file_part =
19-
// reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
20-
File::Path(path) => Ok(reqwest::multipart::Part::file(path).await?),
21-
File::Buf{filename, file, length, mime_type} => {
11+
//This does not compile under ci (but does not under ci?!?)?
12+
//Self::Path(path) => Ok(reqwest::multipart::Part::file(path).await?),
13+
Self::Path(path) => {
14+
//The generator likes to generate this in 7.20.0
15+
let file = ::tokio::fs::File::open(&path).await?;
16+
let stream = ::tokio_util::codec::FramedRead::new(file, ::tokio_util::codec::BytesCodec::new());
17+
let file_name = path
18+
.file_name()
19+
.map(|n| n.to_string_lossy().to_string())
20+
.unwrap_or_default();
21+
let file_part =
22+
::reqwest::multipart::Part::stream(::reqwest::Body::wrap_stream(stream)).file_name(file_name);
23+
24+
Ok(file_part)
25+
}
26+
Self::Buf{filename, file, length, mime_type} => {
2227
let part = if let Some(length) = length {
23-
reqwest::multipart::Part::stream_with_length(file, length)
28+
::reqwest::multipart::Part::stream_with_length(file, length)
2429
} else {
25-
reqwest::multipart::Part::stream(file)
30+
::reqwest::multipart::Part::stream(file)
2631
}
2732
.file_name(filename)
2833
.mime_str(&*mime_type)?;

src/patches/better_file_upload.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ pub enum File<'a> {
44
Path(::std::path::PathBuf),
55
Buf {
66
filename: ::std::borrow::Cow<'static, str>,
7-
file: reqwest::Body,
8-
length: Option<u64>,
7+
file: ::reqwest::Body,
8+
length: ::core::option::Option<u64>,
99
mime_type: ::std::borrow::Cow<'a, str>,
1010
},
1111
}
@@ -15,26 +15,35 @@ impl File<'_> {
1515
self,
1616
) -> Result<::reqwest::multipart::Part, crate::apis::Error<T>> {
1717
match self {
18-
//The generator likes to generate this in 7.20.0. Why? Let's not?
19-
// let file = TokioFile::open(&p_form_file).await?;
20-
// let stream = FramedRead::new(file, BytesCodec::new());
21-
// let file_name = p_form_file
22-
// .file_name()
23-
// .map(|n| n.to_string_lossy().to_string())
24-
// .unwrap_or_default();
25-
// let file_part =
26-
// reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
27-
File::Path(path) => Ok(reqwest::multipart::Part::file(path).await?),
28-
File::Buf {
18+
//This does not compile under ci (but does not under ci?!?)?
19+
//Self::Path(path) => Ok(reqwest::multipart::Part::file(path).await?),
20+
Self::Path(path) => {
21+
//The generator likes to generate this in 7.20.0
22+
let file = ::tokio::fs::File::open(&path).await?;
23+
let stream = ::tokio_util::codec::FramedRead::new(
24+
file,
25+
::tokio_util::codec::BytesCodec::new(),
26+
);
27+
let file_name = path
28+
.file_name()
29+
.map(|n| n.to_string_lossy().to_string())
30+
.unwrap_or_default();
31+
let file_part =
32+
::reqwest::multipart::Part::stream(::reqwest::Body::wrap_stream(stream))
33+
.file_name(file_name);
34+
35+
Ok(file_part)
36+
}
37+
Self::Buf {
2938
filename,
3039
file,
3140
length,
3241
mime_type,
3342
} => {
3443
let part = if let Some(length) = length {
35-
reqwest::multipart::Part::stream_with_length(file, length)
44+
::reqwest::multipart::Part::stream_with_length(file, length)
3645
} else {
37-
reqwest::multipart::Part::stream(file)
46+
::reqwest::multipart::Part::stream(file)
3847
}
3948
.file_name(filename)
4049
.mime_str(&*mime_type)?;

0 commit comments

Comments
 (0)