uploadImages method
Uploads the images from the given report
. If goldenOnly
is true
then only the images marked as golden compatible will be uploaded.
Implementation
Future<void> uploadImages(
TestReport report, {
bool goldenOnly = false,
}) async {
if (!kIsWeb) {
final images = goldenOnly == true
? report.images.where((image) => image.goldenCompatible == true)
: report.images;
final hashes = <String>{};
for (var image in images) {
if (!hashes.contains(image.hash)) {
hashes.add(image.hash);
final actualImagePath = imagePath ?? 'images';
final ref =
storage.ref().child(actualImagePath).child('${image.hash}.png');
final uploadTask = ref.putData(
image.image!,
SettableMetadata(contentType: 'image/png'),
);
var lastProgress = -10;
uploadTask.snapshotEvents.listen((event) {
final progress = event.bytesTransferred ~/ event.totalBytes;
if (lastProgress + 10 <= progress) {
_logger.log(Level.FINER, 'Image: ${image.hash} -- $progress%');
lastProgress = progress;
}
});
try {
await uploadTask;
_logger.log(Level.FINER, 'Image: ${image.hash} -- COMPLETE');
} catch (e, stack) {
_logger.severe(
'Error writing: [$actualImagePath/${image.hash}.png]',
e,
stack);
rethrow;
}
}
}
}
}