createMessageImage method
Implementation
@override
Future<RuutMessage> createMessageImage(File file) async {
try {
final uri =
'/public/api/v1/inboxes/${RuutChatClientApiInterceptor.INTERCEPTOR_INBOX_IDENTIFIER_PLACEHOLDER}/contacts/${RuutChatClientApiInterceptor.INTERCEPTOR_CONTACT_IDENTIFIER_PLACEHOLDER}/conversations/${RuutChatClientApiInterceptor.INTERCEPTOR_CONVERSATION_IDENTIFIER_PLACEHOLDER}/messages';
FormData formData = FormData.fromMap({
'[attachments][]': await MultipartFile.fromFile(file.path,
filename: "Attachment-${file}",
contentType: MediaType('image', 'png')),
});
final response = await _dio.post(uri,
data: formData,
options: Options(headers: {"Content-Type": "multipart/form-data"}));
print("this is called ${formData.fields}");
if ((response.statusCode ?? 0).isBetween(199, 300)) {
print("this is the response for server ${response.data}");
return RuutMessage.fromJson(response.data);
} else {
throw RuutClientException(response.statusMessage ?? "unknown error",
RuutClientExceptionType.SEND_MESSAGE_FAILED);
}
} on DioException catch (e) {
throw RuutClientException(
e.message ?? '', RuutClientExceptionType.SEND_MESSAGE_FAILED);
}
}