Upload thumbnail along with the file
This commit is contained in:
parent
4b63196e34
commit
2e39f2e90a
2 changed files with 26 additions and 2 deletions
|
@ -4,6 +4,7 @@ import 'dart:io' as io;
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:photos/core/constants.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/db/files_db.dart';
|
||||
import 'package:photos/events/photo_upload_event.dart';
|
||||
|
@ -245,13 +246,25 @@ class PhotoSyncManager {
|
|||
}
|
||||
|
||||
Future<File> _uploadEncryptedFile(File file) async {
|
||||
final key = Configuration.instance.getKey("hello");
|
||||
|
||||
final filePath = (await (await file.getAsset()).originFile).path;
|
||||
final encryptedFileName = file.generatedID.toString() + ".aes";
|
||||
final encryptedFilePath = _encryptedFilesDirectory + encryptedFileName;
|
||||
final fileIV = CryptoUtil.getBase64EncodedSecureRandomString(length: 16);
|
||||
final key = Configuration.instance.getKey("hello");
|
||||
await CryptoUtil.encryptFile(filePath, encryptedFilePath, key, fileIV);
|
||||
|
||||
final thumbnailData = (await (await file.getAsset())
|
||||
.thumbDataWithSize(THUMBNAIL_LARGE_SIZE, THUMBNAIL_LARGE_SIZE));
|
||||
final encryptedThumbnailName =
|
||||
file.generatedID.toString() + "_thumbnail.aes";
|
||||
final encryptedThumbnailPath =
|
||||
_encryptedFilesDirectory + encryptedThumbnailName;
|
||||
final thumbnailIV =
|
||||
CryptoUtil.getBase64EncodedSecureRandomString(length: 16);
|
||||
await CryptoUtil.encryptData(
|
||||
thumbnailData, encryptedThumbnailPath, key, thumbnailIV);
|
||||
|
||||
final metadata = jsonEncode(file.getMetadata());
|
||||
final metadataIV =
|
||||
CryptoUtil.getBase64EncodedSecureRandomString(length: 16);
|
||||
|
@ -260,6 +273,9 @@ class PhotoSyncManager {
|
|||
"file": MultipartFile.fromFileSync(encryptedFilePath,
|
||||
filename: encryptedFileName),
|
||||
"fileIV": fileIV,
|
||||
"thumbnail": MultipartFile.fromFileSync(encryptedThumbnailPath,
|
||||
filename: encryptedThumbnailName),
|
||||
"thumbnailIV": thumbnailIV,
|
||||
"metadata": encryptedMetadata,
|
||||
"metadataIV": metadataIV,
|
||||
});
|
||||
|
|
|
@ -19,7 +19,6 @@ class CryptoUtil {
|
|||
return encrypter.decrypt(Encrypted.fromBase64(cipherText));
|
||||
}
|
||||
|
||||
// Encrypts a file and returns the IV that was used
|
||||
static Future<void> encryptFile(String sourcePath, String destinationPath,
|
||||
String base64Key, String base64IV) async {
|
||||
final encrypter = AesCrypt("hello");
|
||||
|
@ -28,4 +27,13 @@ class CryptoUtil {
|
|||
encrypter.setOverwriteMode(AesCryptOwMode.on);
|
||||
await encrypter.encryptFile(sourcePath, destinationPath);
|
||||
}
|
||||
|
||||
static Future<void> encryptData(Uint8List source, String destinationPath,
|
||||
String base64Key, String base64IV) async {
|
||||
final encrypter = AesCrypt("hello");
|
||||
encrypter.aesSetParams(Key.fromBase64(base64Key).bytes,
|
||||
IV.fromBase64(base64IV).bytes, AesMode.cbc);
|
||||
encrypter.setOverwriteMode(AesCryptOwMode.on);
|
||||
await encrypter.encryptDataToFile(source, destinationPath);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue