uploadFile static method
获取网络参数*
Implementation
static void uploadFile(String path,Function(HttpResult result) callback) async{
File file=File(path);
bool exists=await file.exists();
//文件不存在
if(!exists){
return;
}
String srcFileName = file.path.split('/').last;
//包名-账号-文件名
String fileName="flutter_smart_ptt-${pocChangeNotifier.account.toString()}-$srcFileName";
Log.i(tag, "uploadFile:fileName:$fileName");
Map<String, String?>? header = {};
header['Method'] = "UploadLog";
header['UserId'] = "328140";
header['RecvId'] = "0";
header['Name'] = fileName;
header['Content-Length'] = file.lengthSync().toString();
String url=Url_UploadLog_CN;
Log.i(tag, "uploadFile:try:url:$url");
post(url, header, file.readAsBytesSync(), (HttpResult result){
if(result.success){
callback(result);
}else{
//失败使用国外地址再试一次
if(url==Url_UploadLog_CN){
url=Url_UploadLog_EN;
Log.i(tag, "uploadFile:try again:url:$url");
post(url, header, file.readAsBytesSync(),callback);
}
}
});
}