[mob] Additional check for fileSize for multipart upload

This commit is contained in:
Neeraj Gupta
2024-09-05 14:10:26 +05:30
committed by Neeraj Gupta
parent 1b6dbbc288
commit 7c2ce513df
4 changed files with 12 additions and 1 deletions

View File

@@ -250,6 +250,7 @@ class UploadLocksDB {
}
final row = rows.first;
final objectKey = row[_trackUploadTable.columnObjectKey] as String;
final encFileSize = row[_trackUploadTable.columnEncryptedFileSize] as int;
final partsStatus = await db.query(
_partsTable.table,
where: '${_partsTable.columnObjectKey} = ?',
@@ -285,6 +286,7 @@ class UploadLocksDB {
.byName(row[_trackUploadTable.columnStatus] as String),
partUploadStatus: partUploadStatus,
partETags: partETags,
encFileSize: encFileSize,
partSize: row[_trackUploadTable.columnPartSize] as int,
);
}

View File

@@ -33,6 +33,7 @@ class MultipartInfo {
final List<bool>? partUploadStatus;
final Map<int, String>? partETags;
final int? partSize;
final int encFileSize;
final MultipartUploadURLs urls;
final MultipartStatus status;
@@ -41,6 +42,7 @@ class MultipartInfo {
this.partETags,
this.partSize,
this.status = MultipartStatus.pending,
required this.encFileSize,
required this.urls,
});
}

View File

@@ -148,10 +148,11 @@ class MultiPartUploader {
Future<String> putMultipartFile(
MultipartUploadURLs urls,
File encryptedFile,
int fileSize,
) async {
// upload individual parts and get their etags
final etags = await _uploadParts(
MultipartInfo(urls: urls),
MultipartInfo(urls: urls, encFileSize: fileSize),
encryptedFile,
);
@@ -180,6 +181,11 @@ class MultiPartUploader {
}
final int encFileLength = encryptedFile.lengthSync();
if (encFileLength != partInfo.encFileSize) {
throw Exception(
"File size mismatch. Expected ${partInfo.encFileSize} but got $encFileLength",
);
}
// Start parts upload
int count = 0;
while (i < partsLength) {

View File

@@ -685,6 +685,7 @@ class FileUploader {
fileObjectKey = await _multiPartUploader.putMultipartFile(
fileUploadURLs,
encryptedFile,
encFileSize,
);
}
// in case of multipart, upload the thumbnail towards the end to avoid