Hello, I’ve been trying to build a flutter app with gemini API. It will be like a chatbot with additional features. I try to send a media file to Gemini but I get this error:
rror: GeminiException => This exception was thrown because the response has a status code of 404 and RequestOptions.validateStatus was configured to throw for this status code.
I/flutter (12001): The status code of 404 has the following meaning: “Client error - the request contains bad syntax or cannot be fulfilled”
I/flutter (12001): Read more about status codes at HTTP response status codes - HTTP | MDN
I/flutter (12001): In order to resolve this exception you typically have either to verify and fix your request code or you have to fix the server code.
Before sending a prompt to Gemini it was working fine but now even when I delete the prompt it doesn’t work.
void _sendMessage(ChatMessage chatMessage) {
setState(() {
messages = [chatMessage, ...messages];
});
try {
String question = chatMessage.text;
List<Uint8List>? images;
if (chatMessage.medias?.isNotEmpty ?? false) {
images = [
File(chatMessage.medias!.first.url).readAsBytesSync(),
];
}
gemini
.streamGenerateContent(
question,
images: images,
)
.listen((event) {
ChatMessage? lastMessage = messages.firstOrNull;
if (lastMessage != null && lastMessage.user == geminiUser) {
lastMessage = messages.removeAt(0);
String response = event.content?.parts?.fold(
"", (previous, current) => "$previous ${current.text}") ??
"";
lastMessage.text += response;
setState(
() {
messages = [lastMessage!, ...messages];
},
);
} else {
String response = event.content?.parts?.fold(
"", (previous, current) => "$previous ${current.text}") ??
"";
ChatMessage message = ChatMessage(
user: geminiUser,
createdAt: DateTime.now(),
text: response,
);
setState(() {
messages = [message, ...messages];
});
}
});
} catch (e) {
print(e);
}
}
I get the error at .listen(event) part
Thanks in advance!