uploadFile static method
Tải lên một tệp File
Implementation
static Future<String?> uploadFile({
required File file,
required conversationId,
Function(double progress)? onProgress,
}) async {
chatV2Print("Upload file: length=${file.length} path=${file.path} ");
try {
final bytes = await file.readAsBytes();
final path = file.path;
NetworkResponse response =
await BucketFolderRepo().uploadBucketFilesFromAdmin(bytes, path, {
"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 done url=$url");
return url;
} else {
chatV2Print("Lỗi khi tải lên tệp: ${response.msg}");
onProgress?.call(-1);
}
} catch (e) {
chatV2Print("Lỗi khi tải lên tệp: $e");
onProgress?.call(-1);
}
return null;
}