26-5-2
This commit is contained in:
@@ -483,11 +483,13 @@ class ScanDocumentsByApi extends GetxController {
|
|||||||
} else {}
|
} else {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo upload images and fields
|
|
||||||
Future<String> uploadImagePortrate() async {
|
Future<String> uploadImagePortrate() async {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
update();
|
update();
|
||||||
|
|
||||||
|
final String token = box.read(BoxName.jwt)?.toString().split(AppInformation.addd)[0] ?? '';
|
||||||
|
final String fingerPrint = box.read(BoxName.deviceFingerprint)?.toString() ?? '';
|
||||||
|
|
||||||
var request = http.MultipartRequest(
|
var request = http.MultipartRequest(
|
||||||
'POST',
|
'POST',
|
||||||
Uri.parse(AppLink.uploadImagePortrate),
|
Uri.parse(AppLink.uploadImagePortrate),
|
||||||
@@ -498,22 +500,18 @@ class ScanDocumentsByApi extends GetxController {
|
|||||||
);
|
);
|
||||||
|
|
||||||
request.headers.addAll({
|
request.headers.addAll({
|
||||||
"Content-Type": "multipart/form-data",
|
'Authorization': 'Bearer $token',
|
||||||
'Authorization':
|
'X-Device-FP': fingerPrint,
|
||||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
|
||||||
});
|
});
|
||||||
request.fields['driverID'] = box.read(BoxName.driverID).toString();
|
request.fields['driverID'] = box.read(BoxName.driverID).toString();
|
||||||
|
|
||||||
var response = await request.send();
|
var response = await request.send();
|
||||||
|
|
||||||
var responseData = await response.stream.toBytes();
|
var responseData = await response.stream.toBytes();
|
||||||
var responseString = String.fromCharCodes(responseData);
|
var responseString = String.fromCharCodes(responseData);
|
||||||
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
update();
|
update();
|
||||||
|
|
||||||
// Print the response string
|
|
||||||
|
|
||||||
return responseString;
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -304,27 +304,19 @@ class ImageController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadImage(File file, Map data, String link) async {
|
uploadImage(File file, Map data, String link) async {
|
||||||
var request = http.MultipartRequest(
|
final String token = r(box.read(BoxName.jwt)).split(AppInformation.addd)[0];
|
||||||
'POST',
|
final String fingerPrint = box.read(BoxName.deviceFingerprint)?.toString() ?? '';
|
||||||
Uri.parse(link),
|
|
||||||
);
|
var request = http.MultipartRequest('POST', Uri.parse(link));
|
||||||
Log.print('request: ${request}');
|
Log.print('uploadImage -> $link');
|
||||||
|
|
||||||
|
request.headers.addAll({
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
'X-Device-FP': fingerPrint,
|
||||||
|
});
|
||||||
|
|
||||||
var length = await file.length();
|
var length = await file.length();
|
||||||
var stream = http.ByteStream(file.openRead());
|
var stream = http.ByteStream(file.openRead());
|
||||||
final headers = {
|
|
||||||
'Authorization':
|
|
||||||
'Bearer ${r(box.read(BoxName.jwt)).split(AppInformation.addd)[0]}',
|
|
||||||
'X-HMAC-Auth': '${box.read(BoxName.hmac)}',
|
|
||||||
};
|
|
||||||
var multipartFile = http.MultipartFile(
|
|
||||||
'image',
|
|
||||||
stream,
|
|
||||||
length,
|
|
||||||
filename: basename(file.path),
|
|
||||||
);
|
|
||||||
request.headers.addAll(headers);
|
|
||||||
// Set the file name to the driverID
|
|
||||||
|
|
||||||
request.files.add(
|
request.files.add(
|
||||||
http.MultipartFile(
|
http.MultipartFile(
|
||||||
'image',
|
'image',
|
||||||
@@ -336,36 +328,29 @@ class ImageController extends GetxController {
|
|||||||
data.forEach((key, value) {
|
data.forEach((key, value) {
|
||||||
request.fields[key] = value;
|
request.fields[key] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
var myrequest = await request.send();
|
var myrequest = await request.send();
|
||||||
var res = await http.Response.fromStream(myrequest);
|
var res = await http.Response.fromStream(myrequest);
|
||||||
|
Log.print('uploadImage response [${res.statusCode}]: ${res.body}');
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
Log.print('jsonDecode(res.body): ${jsonDecode(res.body)}');
|
|
||||||
return jsonDecode(res.body);
|
return jsonDecode(res.body);
|
||||||
} else {
|
} else {
|
||||||
throw Exception(
|
throw Exception('Failed to upload image: ${res.statusCode} - ${res.body}');
|
||||||
'Failed to upload image: ${res.statusCode} - ${res.body}');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadNewCar(File file, Map data, String link) async {
|
uploadNewCar(File file, Map data, String link) async {
|
||||||
var request = http.MultipartRequest(
|
final String token = r(box.read(BoxName.jwt)).split(AppInformation.addd)[0];
|
||||||
'POST',
|
final String fingerPrint = box.read(BoxName.deviceFingerprint)?.toString() ?? '';
|
||||||
Uri.parse(link),
|
|
||||||
);
|
var request = http.MultipartRequest('POST', Uri.parse(link));
|
||||||
|
request.headers.addAll({
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
'X-Device-FP': fingerPrint,
|
||||||
|
});
|
||||||
|
|
||||||
var length = await file.length();
|
var length = await file.length();
|
||||||
var stream = http.ByteStream(file.openRead());
|
var stream = http.ByteStream(file.openRead());
|
||||||
var multipartFile = http.MultipartFile(
|
|
||||||
'image',
|
|
||||||
stream,
|
|
||||||
length,
|
|
||||||
filename: basename(file.path),
|
|
||||||
);
|
|
||||||
request.headers.addAll({
|
|
||||||
'Authorization':
|
|
||||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
|
|
||||||
});
|
|
||||||
// Set the file name to the driverID
|
|
||||||
request.files.add(
|
request.files.add(
|
||||||
http.MultipartFile(
|
http.MultipartFile(
|
||||||
'image',
|
'image',
|
||||||
@@ -377,14 +362,14 @@ class ImageController extends GetxController {
|
|||||||
data.forEach((key, value) {
|
data.forEach((key, value) {
|
||||||
request.fields[key] = value;
|
request.fields[key] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
var myrequest = await request.send();
|
var myrequest = await request.send();
|
||||||
var res = await http.Response.fromStream(myrequest);
|
var res = await http.Response.fromStream(myrequest);
|
||||||
|
Log.print('uploadNewCar response [${res.statusCode}]: ${res.body}');
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
Log.print('jsonDecode(res.body): ${jsonDecode(res.body)}');
|
|
||||||
return jsonDecode(res.body);
|
return jsonDecode(res.body);
|
||||||
} else {
|
} else {
|
||||||
throw Exception(
|
throw Exception('Failed to upload image: ${res.statusCode} - ${res.body}');
|
||||||
'Failed to upload image: ${res.statusCode} - ${res.body}');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,16 +405,21 @@ class ImageController extends GetxController {
|
|||||||
File compressedImage = await compressImage(File(croppedFile!.path));
|
File compressedImage = await compressImage(File(croppedFile!.path));
|
||||||
print('link =$link');
|
print('link =$link');
|
||||||
try {
|
try {
|
||||||
await uploadImage(
|
var response = await uploadImage(
|
||||||
compressedImage,
|
compressedImage,
|
||||||
{'driverID': (box.read(BoxName.driverID)), 'imageType': imageType},
|
{'driverID': (box.read(BoxName.driverID)), 'imageType': imageType},
|
||||||
link,
|
link,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Save the returned URL from the V3 backend to local storage
|
||||||
|
if (response != null && response['status'] == 'success' && response['message'] != null) {
|
||||||
|
if (response['message']['file_link'] != null) {
|
||||||
|
box.write(BoxName.driverPhotoUrl, response['message']['file_link'].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.print('e: ${e}');
|
Log.print('e: ${e}');
|
||||||
mySnackeBarError('Image Upload Failed'.tr);
|
mySnackeBarError('Image Upload Failed'.tr);
|
||||||
// Get.snackbar('Image Upload Failed'.tr, e.toString(),
|
|
||||||
// backgroundColor: AppColor.redColor);
|
|
||||||
} finally {
|
} finally {
|
||||||
isloading = false;
|
isloading = false;
|
||||||
update();
|
update();
|
||||||
@@ -437,42 +427,36 @@ class ImageController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadImagePicture(File file, Map data, String link) async {
|
uploadImagePicture(File file, Map data, String link) async {
|
||||||
var request = http.MultipartRequest(
|
final String token = r(box.read(BoxName.jwt)).split(AppInformation.addd)[0];
|
||||||
'POST',
|
final String fingerPrint = box.read(BoxName.deviceFingerprint)?.toString() ?? '';
|
||||||
Uri.parse(link), //'https://ride.mobile-app.store/uploadImage1.php'
|
|
||||||
);
|
var request = http.MultipartRequest('POST', Uri.parse(link));
|
||||||
|
request.headers.addAll({
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
'X-Device-FP': fingerPrint,
|
||||||
|
});
|
||||||
|
|
||||||
var length = await file.length();
|
var length = await file.length();
|
||||||
var stream = http.ByteStream(file.openRead());
|
var stream = http.ByteStream(file.openRead());
|
||||||
var multipartFile = http.MultipartFile(
|
|
||||||
'image',
|
|
||||||
stream,
|
|
||||||
length,
|
|
||||||
filename: basename(file.path),
|
|
||||||
);
|
|
||||||
request.headers.addAll({
|
|
||||||
'Authorization':
|
|
||||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
|
|
||||||
});
|
|
||||||
// Set the file name to the driverID
|
|
||||||
request.files.add(
|
request.files.add(
|
||||||
http.MultipartFile(
|
http.MultipartFile(
|
||||||
'image',
|
'image',
|
||||||
stream,
|
stream,
|
||||||
length,
|
length,
|
||||||
filename: '${(box.read(BoxName.driverID))}.jpg',
|
filename: '${box.read(BoxName.driverID)}.jpg',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
data.forEach((key, value) {
|
data.forEach((key, value) {
|
||||||
request.fields[key] = value;
|
request.fields[key] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
var myrequest = await request.send();
|
var myrequest = await request.send();
|
||||||
var res = await http.Response.fromStream(myrequest);
|
var res = await http.Response.fromStream(myrequest);
|
||||||
|
Log.print('uploadImagePicture response [${res.statusCode}]: ${res.body}');
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
return jsonDecode(res.body);
|
return jsonDecode(res.body);
|
||||||
} else {
|
} else {
|
||||||
throw Exception(
|
throw Exception('Failed to upload image: ${res.statusCode} - ${res.body}');
|
||||||
'Failed to upload image: ${res.statusCode} - ${res.body}');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -308,9 +308,13 @@ class UserHeader extends StatelessWidget {
|
|||||||
child: controller.isloading
|
child: controller.isloading
|
||||||
? const CircularProgressIndicator(color: Colors.white)
|
? const CircularProgressIndicator(color: Colors.white)
|
||||||
: CircleAvatar(
|
: CircleAvatar(
|
||||||
// محاولة تحميل الصورة
|
backgroundImage: NetworkImage((box
|
||||||
backgroundImage: NetworkImage(
|
.read(BoxName.driverPhotoUrl)
|
||||||
'${AppLink.server}/portrate_captain_image/${box.read(BoxName.driverID)}.jpg'),
|
?.toString()
|
||||||
|
.isNotEmpty ==
|
||||||
|
true)
|
||||||
|
? box.read(BoxName.driverPhotoUrl)
|
||||||
|
: '${AppLink.server}/portrate_captain_image/${box.read(BoxName.driverID)}.jpg'),
|
||||||
|
|
||||||
// [تعديل هام]: في حال فشل تحميل الصورة (غير موجودة)
|
// [تعديل هام]: في حال فشل تحميل الصورة (غير موجودة)
|
||||||
onBackgroundImageError: (exception, stackTrace) {
|
onBackgroundImageError: (exception, stackTrace) {
|
||||||
|
|||||||
Reference in New Issue
Block a user