uploadFilesToS3 function
Implementation
Future<void> uploadFilesToS3(
List<FileMetadata> uploadLinks, List<FileMetadata> files) async {
final s3Api = http.Client();
await Future.wait(uploadLinks.map((link) async {
final file = files.firstWhereOrNull((x) =>
x.fileName == link.fileName &&
(x.path == null || x.path == "" || x.path == link.path));
if (file == null) {
throw StateError("Can't find file ${link.path}${link.fileName}!");
}
final content = file.index == "" || file.index == null
? file.content
: File(file.index!).readAsBytesSync();
await s3Api.put(Uri.parse(link.url!), body: content);
ApillonLogger.log('File uploaded: ${file.fileName}');
}));
s3Api.close();
}