Browse Source

add await for file download

master
Inex Code 4 months ago
parent
commit
449640699f
  1. 4
      bin/server.dart

4
bin/server.dart

@ -79,14 +79,14 @@ Future<void> _postOnMastodon(reqJson) async { @@ -79,14 +79,14 @@ Future<void> _postOnMastodon(reqJson) async {
final photos =
attachments.where((attachment) => attachment['type'] == 'photo');
final photoUrls = photos.map((photo) {
final photoUrls = photos.map((photo) async {
final photoUrl = photo['photo']['sizes'].last['url'];
// Generate a random filename.
// Add the extension '.jpg'.
final photoFilename = '${DateTime.now().millisecondsSinceEpoch}-${photoUrl.split('/').last.split('?').first.substring(0, 10)}.jpg';
final photoPath =
'${Directory.systemTemp.path}/$photoFilename';
dio.download(photoUrl, photoPath);
await dio.download(photoUrl, photoPath);
return photoPath;
});

Loading…
Cancel
Save