uploadFileData static method
Tải lên dữ liệu dạng Uint8List
Implementation
static Future<String?> uploadFileData({
required conversationId,
required Uint8List data,
required String fileName,
bool isNeedCompress = false,
Function(double progress)? onProgress,
}) async {
chatV2Print("Upload file data: length=${data.length} fileName=$fileName ");
try {
// Xử lý nén dữ liệu nếu cần
// if (isNeedCompress) {
// print("Nén dữ liệu tệp");
// // Thêm logic nén tại đây nếu cần
// print("Dữ liệu đã được nén");
// }
NetworkResponse response =
await BucketFolderRepo().uploadBucketFilesFromAdmin(data, fileName, {
"label": conversationId,
"purpose": 'file in conversation',
"folderUuid": '42c232c5-0bad-11f0-8164-26bbd886b062', //chat-assets
"instanceId": "",
"fileCategory": "",
"compressionOptions": ""
}, (int count, int total) {
if (onProgress != null) {
onProgress(count / total);
}
});
if (response.isSuccess && response.data != null) {
CommonMedia commonMedia = response.data;
String url = commonMedia.url ?? '';
chatV2Print("Upload file data done url=$url");
return url;
} else {
chatV2Print("Lỗi khi tải lên dữ liệu: ${response.msg}");
onProgress?.call(-1);
}
} catch (e) {
chatV2Print("Lỗi khi tải lên dữ liệu: $e");
onProgress?.call(-1);
}
return null;
}