postAttachment static method
Implementation
static Future<Attachment?> postAttachment(File file,
{bool isNote = false}) async {
Attachment? attachment;
ChatController chatController = Get.find();
String idConversation = chatController.conversation.value?.id ?? "";
String idAssistant = chatController.assistant.value?.id ?? "";
String conversationToken =
chatController.conversation.value?.token ?? "";
dio.FormData formData = dio.FormData.fromMap({
"type": isNote ? "NOTE" : FileService.getFileType(file.path),
"file": dio.MultipartFile.fromBytes(
file.readAsBytesSync(),
filename: basename(file.path),
)
});
if (idAssistant != "" && idConversation != "" && conversationToken != "") {
await ApiService.call(
ApiUrls.conversationAttachmentsUrl(idAssistant, idConversation),
RequestType.post,
data: formData,
headers: {
"Content-Type": "multipart/form-data",
"Conversation-Token": conversationToken,
},
onSuccess: (response) => attachment = Attachment.fromMap(response.data),
onError: (e) => showErrorSnackbar(
"${Strings.apiErrorGeneric.tr} ${Strings.attachmentUploadFailed.tr}"),
);
return attachment;
}
return null;
}