YWDGqsMTOYCGMnYn method
Implementation
Future<void> YWDGqsMTOYCGMnYn({
required String filePath,
required String dir,
String? fileExt,
Function(int count, int total)? onProgress,
Function(bool isSuccess, String? url, String? error)? onFinish,
}) async {
if (!XnTmvYcKqTTNDFGO) {
onFinish?.call(false, null, "can not upload file");
return;
}
final kb = await XFile(filePath).length() / 1024.0;
final sizeKB = kb < 1 ? 1 : kb.toInt();
lZUCgdYJMjUzohKy.AgJxpuBoMXJsVIUQ.EEMfBymGDbvUyfjO("prepareFileUpload", data: {
"sizeKB": sizeKB,
}, ack: (isSuccess, results, code, msg) async {
if (!isSuccess) {
onFinish?.call(false, null, msg);
return;
}
void FBUINQPwTFpvcOfV(String path) {
final url = ohJMyiFoPLLAApRa != null ? "${ohJMyiFoPLLAApRa}/$path" : "https://${bOEgOkSqiRFNcTDU}.${oFJvGbRGqNhyfrzp}/$path";
lZUCgdYJMjUzohKy.AgJxpuBoMXJsVIUQ.EEMfBymGDbvUyfjO("finishFileUpload", data: {
"url": url,
}, ack: (isSuccess, results, code, msg) async {
if (!isSuccess) {
onFinish?.call(false, null, msg);
return;
}
onFinish?.call(true, url, null);
});
}
Future<void> UTSfvNZXQauWLatF() async {
try {
final path = "client/${dir}/flutter_${Uuid().v4().replaceAll("-", "")}.${fileExt}";
final response = await Client().putObject(
await XFile(filePath).readAsBytes(),
path,
option: PutRequestOption(
override: true,
aclModel: AclMode.publicRead,
storageType: StorageType.standard,
onSendProgress: (count, total) {
onProgress?.call(count, total);
},
),
);
if (response.statusCode != HttpStatus.ok) {
onFinish?.call(false, null, response.statusMessage ?? "HTTP ${response.statusCode ?? "Unknown"}");
return null;
}
FBUINQPwTFpvcOfV(path);
} catch (e) {
onFinish?.call(false, null, e.toString());
}
}
try {
final path = "client/${dir}/flutter_${Uuid().v4().replaceAll("-", "")}.${filePath.split("/").last.split(".").last}";
final response = await Client().putObjectFile(
filePath,
fileKey: path,
option: PutRequestOption(
override: true,
aclModel: AclMode.publicRead,
storageType: StorageType.standard,
onSendProgress: (count, total) {
onProgress?.call(count, total);
},
),
);
if (response.statusCode != HttpStatus.ok) {
onFinish?.call(false, null, response.statusMessage ?? "HTTP ${response.statusCode ?? "Unknown"}");
return null;
}
FBUINQPwTFpvcOfV(path);
} catch (e) {
UTSfvNZXQauWLatF();
}
});
}