40 lines
1.2 KiB
Dart
40 lines
1.2 KiB
Dart
import 'dart:convert'; // For jsonEncode
|
|
import 'package:firebase_remote_config/firebase_remote_config.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
Future<void> callHumProcessImage(String targetImageUrl) async {
|
|
// 1. GET THE URL FROM REMOTE CONFIG
|
|
final remoteConfig = FirebaseRemoteConfig.instance;
|
|
String functionUrl = remoteConfig.getString('fn_ai_parse_image');
|
|
|
|
// Safety check: ensure we actually got a URL
|
|
if (functionUrl.isEmpty) {
|
|
print("Error: Remote Config URL is empty.");
|
|
return;
|
|
}
|
|
|
|
final url = Uri.parse(functionUrl);
|
|
|
|
try {
|
|
// 2. Make the POST request
|
|
final response = await http.post(
|
|
url,
|
|
headers: {'Content-Type': 'application/json'},
|
|
// 3. Encode the body as JSON, inserting the dynamic URL
|
|
body: jsonEncode({'imageUrl': targetImageUrl}),
|
|
);
|
|
|
|
// 4. Check the response
|
|
if (response.statusCode == 200) {
|
|
print('Success: ${response.body}');
|
|
// You can parse the response body here if your function returns data
|
|
// final data = jsonDecode(response.body);
|
|
} else {
|
|
print('Request failed with status: ${response.statusCode}.');
|
|
print('Response body: ${response.body}');
|
|
}
|
|
} catch (e) {
|
|
print('Error sending request: $e');
|
|
}
|
|
}
|