Skip to content

Commit e44a0ff

Browse files
authored
Merge pull request #3364 from jarhodes314/bug/file-transfer-no-content
fix: ensure file transfer service always writes uploaded file
2 parents 09a0d00 + 7b712bb commit e44a0ff

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

crates/core/tedge_agent/src/http_server/file_transfer.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use tokio::io;
2626
use tokio::io::AsyncBufReadExt;
2727
use tokio::io::AsyncWriteExt;
2828
use tokio::io::BufReader;
29+
use tokio::io::BufWriter;
2930
use tokio_util::io::ReaderStream;
3031

3132
pub(crate) fn file_transfer_router(file_transfer_dir: Utf8PathBuf) -> Router {
@@ -128,17 +129,23 @@ async fn stream_request_body_to_path(
128129
path: &Utf8Path,
129130
body_stream: &mut Body,
130131
) -> anyhow::Result<()> {
131-
let mut buffer = File::create(path)
132-
.await
133-
.with_context(|| format!("creating {path:?}"))?;
132+
let mut buffer = BufWriter::new(
133+
File::create(path)
134+
.await
135+
.with_context(|| format!("creating {path:?}"))?,
136+
);
134137
while let Some(data) = body_stream.next().await {
135138
let data =
136139
data.with_context(|| format!("reading body of uploaded file (destined for {path:?})"))?;
137-
let _bytes_written = buffer
138-
.write(&data)
140+
buffer
141+
.write_all(&data)
139142
.await
140143
.with_context(|| format!("writing to {path:?}"))?;
141144
}
145+
buffer
146+
.flush()
147+
.await
148+
.with_context(|| format!("writing to {path:?}"))?;
142149
Ok(())
143150
}
144151

0 commit comments

Comments
 (0)