Implement artifact download functionality in Flutter web app

Added the downloadArtifact method to the ChatService class, enabling the download of artifacts in the Flutter web application. The function uses the dart:html package to trigger a browser-based file download, allowing users to save artifacts locally. This implementation complements the existing REST API and enhances the user experience.
This commit is contained in:
hunteraraujo
2023-09-06 16:08:51 -07:00
parent 17f284a9ac
commit 3ccffdab19
4 changed files with 56 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:http/http.dart' as http;
class RestApiUtility {
@@ -32,4 +33,19 @@ class RestApiUtility {
throw Exception('Failed to post data');
}
}
Future<Uint8List> getBinary(String endpoint) async {
final response = await http.get(
Uri.parse('$_baseUrl/$endpoint'),
headers: {"Content-Type": "application/octet-stream"},
);
if (response.statusCode == 200) {
return response.bodyBytes;
} else if (response.statusCode == 404) {
throw Exception('Resource not found');
} else {
throw Exception('Failed to load binary data');
}
}
}