Skip to content

Commit c08912d

Browse files
committed
fixed multiple parts not uploading (minimum chunk size issue)
1 parent f3dd376 commit c08912d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

cryptify-back-end/src/main.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use rocket_cors::{AllowedOrigins, CorsOptions};
3838
use serde::{Deserialize, Serialize};
3939
use store::{FileState, Store};
4040

41-
const CHUNK_SIZE: u64 = 1024 * 1024; // 1 MB
41+
const CHUNK_SIZE: u64 = (1024 * 1024)*5; // 5 MB
4242

4343
#[derive(Serialize, Deserialize)]
4444
struct InitBody {
@@ -441,16 +441,21 @@ async fn upload_finalize(
441441
.set_parts(Some(state.s3_parts.clone()))
442442
.build();
443443

444-
let complete_multipart_upload_res = client
444+
client
445445
.complete_multipart_upload()
446446
.bucket(&bucket_name)
447447
.key(uuid)
448448
.upload_id(&state.s3_upload_id)
449449
.multipart_upload(completed_upload)
450450
.send()
451-
.await;
452-
453-
complete_multipart_upload_res.map_err(|_| Error::InternalServerError(Some("Could not complete S3 multipart upload".to_owned())))?;
451+
.await
452+
.map_err(|e| {
453+
log::error!("S3 complete_multipart_upload failed: {:?}", e);
454+
Error::InternalServerError(Some(format!(
455+
"Could not complete S3 multipart upload: {:?}",
456+
e
457+
)))
458+
})?;
454459

455460
// open the file to get the sender
456461
file = client
@@ -571,6 +576,9 @@ async fn rocket() -> _ {
571576
// conditionally mount the file download routes
572577
if s3_client.is_some() {
573578
rocket = rocket.mount("/filedownload", routes![s3fileServer]);
579+
if CHUNK_SIZE < 5 * 1024 * 1024 {
580+
log::warn!("S3 storage is enabled, but CHUNK_SIZE is less than 5 MB. This may lead to failing uploads.");
581+
}
574582
} else {
575583
rocket = rocket.mount("/filedownload", FileServer::from(config.data_dir()));
576584
}

cryptify-front-end/src/Constants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const MAX_UPLOAD_SIZE: number = 2 * 1000 * 1000 * 1000;
1212

1313
// 1Mb chunks
1414
export const FILEREAD_CHUNK_SIZE: number = 1024 * 1024;
15-
export const UPLOAD_CHUNK_SIZE: number = 1024 * 1024;
15+
export const UPLOAD_CHUNK_SIZE: number = (1024 * 1024)*5;
1616

1717
// progress bar smooth time in seconds.
1818
export const SMOOTH_TIME: number = 2;

0 commit comments

Comments
 (0)