Browse Source

fixing upload

master
jefry 4 years ago
parent
commit
2d4bf56fae
4 changed files with 21 additions and 5 deletions
  1. +4
    -2
      lib/asset_logs.dart
  2. +11
    -0
      lib/util/dbHandler.dart
  3. +3
    -1
      lib/util/download_Upload_Handler.dart
  4. +3
    -2
      lib/util/utils.dart

+ 4
- 2
lib/asset_logs.dart View File

@@ -22,9 +22,10 @@ class _AssetLogsState extends State<AssetLogs> {
String search = ''; String search = '';
fetchData()async{ fetchData()async{
var dbName = await DBHelper.database.getDbName(); var dbName = await DBHelper.database.getDbName();
var bUnit = await DBHelper.database.getBUnit();
// result. // result.
var result = await util.JsonDataPostRaw({"dbName" : dbName , "redirect" : "FALSE" , "auditedData" : "FALSE"}, "${prefs.getString(keyClass.hostAddress)??"http://172.16.4.144:3000"}/admin/data/dbDetail");
if(result['STATUS']!='ERROR'){
var result = await util.JsonDataPostRaw({"bUnit":bUnit,"dbName" : dbName , "redirect" : "FALSE" , "auditedData" : "FALSE"}, "${prefs.getString(keyClass.hostAddress)??"http://172.16.4.144:3000"}/admin/data/dbDetail");
if(result['STATUS']!=0){
var arrayList = result['DATA']['nonAuditedData']; var arrayList = result['DATA']['nonAuditedData'];
nonAuditedAsset.clear(); nonAuditedAsset.clear();
for(int i = 0 ; i <arrayList.length ; i++){ for(int i = 0 ; i <arrayList.length ; i++){
@@ -36,6 +37,7 @@ class _AssetLogsState extends State<AssetLogs> {
}); });
} }
else{ else{
print(result);
util.showToast('ALERT', "Can't reach the server."); util.showToast('ALERT', "Can't reach the server.");
Navigator.pop(context); Navigator.pop(context);
} }


+ 11
- 0
lib/util/dbHandler.dart View File

@@ -245,5 +245,16 @@ class DBHelper{
return null; return null;
} }
} }
getBUnit()async{
try{
final database = await db;
var res = await database.rawQuery("SELECT ${columnName.value} FROM ${tableName.key} where ${columnName.key} = 'BUSINESS_UNIT'");
return res.isEmpty?null:res.first[columnName.value];
}
catch(e){
print(e);
return null;
}
}


} }

+ 3
- 1
lib/util/download_Upload_Handler.dart View File

@@ -26,6 +26,7 @@ class file_Trans_Handler {
StreamController _progress = new StreamController<double>(); StreamController _progress = new StreamController<double>();
Stream<double> get progress =>_progress.stream; Stream<double> get progress =>_progress.stream;
var client = new Client(); var client = new Client();
var headers = {'device':'mobile'};
downloadFile(String fileName,String link) async { downloadFile(String fileName,String link) async {
StreamedResponse _response; StreamedResponse _response;
List<int> _bytes = []; List<int> _bytes = [];
@@ -34,7 +35,7 @@ class file_Trans_Handler {
_progress.add(null); _progress.add(null);
try { try {
Request req = new Request('GET', Uri.parse(link)); Request req = new Request('GET', Uri.parse(link));
// req.headers = '';
req.headers.addAll(headers);
_response = await client.send(req).timeout( _response = await client.send(req).timeout(
Duration(seconds: 20)); Duration(seconds: 20));
// _response = await client.get('$link',headers: 'application/json') // _response = await client.get('$link',headers: 'application/json')
@@ -76,6 +77,7 @@ class file_Trans_Handler {
print(_total/1024); print(_total/1024);
try{ try{
var request = MultipartRequest('POST', Uri.parse(link)); var request = MultipartRequest('POST', Uri.parse(link));
request.headers.addAll(headers);
request.files.add(await MultipartFile.fromPath('sqliteDb', file.path)); request.files.add(await MultipartFile.fromPath('sqliteDb', file.path));
request.fields[keyClass.user] = user; request.fields[keyClass.user] = user;




+ 3
- 2
lib/util/utils.dart View File

@@ -21,15 +21,16 @@ class Util{
JsonDataPostRaw(Map jsonData, String url,{timeout:false,duration:10}) async{ JsonDataPostRaw(Map jsonData, String url,{timeout:false,duration:10}) async{
const JsonDecoder decoder = const JsonDecoder(); const JsonDecoder decoder = const JsonDecoder();
try { try {
var headers = {'device':'mobile','Content-type': 'application/json'};
var response; var response;
if (timeout) if (timeout)
response = await http.post( response = await http.post(
'$url', headers: {'Content-type': 'application/json'},
'$url', headers: headers,
body: json.encode(jsonData)).timeout( body: json.encode(jsonData)).timeout(
Duration(seconds: duration)); Duration(seconds: duration));
else else
response = await http.post( response = await http.post(
'$url', headers: {'Content-type': 'application/json'},
'$url', headers: headers,
body: json.encode(jsonData)); body: json.encode(jsonData));
final Map data = decoder.convert(response.body); final Map data = decoder.convert(response.body);
return data; return data;


Loading…
Cancel
Save