File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -290,12 +290,25 @@ impl ObjectStorageBackend {
290290 let mut uploaded: u64 = 0 ;
291291
292292 loop {
293- let bytes_read = file. read ( & mut buf) . await ?;
294- if bytes_read == 0 {
295- break ;
293+ // Read a complete chunk (read() may return short reads with async I/O)
294+ // S3 requires all parts except the last to be >= 5MB
295+ let mut chunk_size = 0 ;
296+ loop {
297+ let bytes_read = file. read ( & mut buf[ chunk_size..] ) . await ?;
298+ if bytes_read == 0 {
299+ break ; // EOF
300+ }
301+ chunk_size += bytes_read;
302+ if chunk_size >= MULTIPART_CHUNK_SIZE {
303+ break ; // Full chunk
304+ }
296305 }
297306
298- let body = ByteStream :: from ( buf[ ..bytes_read] . to_vec ( ) ) ;
307+ if chunk_size == 0 {
308+ break ; // No more data
309+ }
310+
311+ let body = ByteStream :: from ( buf[ ..chunk_size] . to_vec ( ) ) ;
299312 let res = client
300313 . upload_part ( )
301314 . bucket ( & bucket)
@@ -319,7 +332,7 @@ impl ObjectStorageBackend {
319332 . build ( ) ,
320333 ) ;
321334
322- uploaded += bytes_read as u64 ;
335+ uploaded += chunk_size as u64 ;
323336 if let Some ( cb) = progress. as_ref ( ) {
324337 cb ( ( uploaded as f32 / total_len as f32 ) . clamp ( 0.0 , 1.0 ) ) ;
325338 }
You can’t perform that action at this time.
0 commit comments