verifyUploadMetadata method
Verify uploaded file using metadata hash (no download needed).
Implementation
Future<bool> verifyUploadMetadata(String fileUuid, File originalFile) async {
api.log('Verifying upload using metadata check...');
print(' π Hashing local file...');
final localHash = await crypto.hashFile(originalFile);
api.log(' Local SHA-512: $localHash');
print(' π Fetching metadata from server...');
final metadata = await getFileMetadata(fileUuid);
final metaStr = await crypto.tryDecrypt(metadata['metadata'], masterKeys);
final meta = json.decode(metaStr);
final serverHash = meta['hash'] as String?;
if (serverHash == null || serverHash.isEmpty) {
print(' β οΈ No hash in metadata (empty file?)');
return await originalFile.length() == 0;
}
api.log(' Server SHA-512: $serverHash');
final match = localHash == serverHash;
if (match) {
print(' β
Verification successful - hashes match!');
} else {
print(' β Verification failed - hashes differ!');
print(' Local: $localHash');
print(' Server: $serverHash');
}
return match;
}