Update: 2026-06-12 01:23:54
This commit is contained in:
@@ -489,25 +489,58 @@ class ScanDocumentsByApi extends GetxController {
|
||||
|
||||
final String token = box.read(BoxName.jwt)?.toString().split(AppInformation.addd)[0] ?? '';
|
||||
final String fingerPrint = box.read(BoxName.deviceFingerprint)?.toString() ?? '';
|
||||
final String driverID = box.read(BoxName.driverID).toString();
|
||||
final String link = AppLink.uploadImagePortrate;
|
||||
|
||||
var request = http.MultipartRequest(
|
||||
'POST',
|
||||
Uri.parse(AppLink.uploadImagePortrate),
|
||||
);
|
||||
int maxRetries = 3;
|
||||
int attempt = 0;
|
||||
String responseString = '';
|
||||
|
||||
request.files.add(
|
||||
http.MultipartFile.fromBytes('image', imagePortrait),
|
||||
);
|
||||
while (attempt < maxRetries) {
|
||||
attempt++;
|
||||
final client = http.Client();
|
||||
try {
|
||||
Log.print('[UPLOAD_LOGGER] 🚀 [uploadImagePortrate] Attempt $attempt/$maxRetries started. Link: $link, Image Size: ${imagePortrait.length} bytes');
|
||||
|
||||
var request = http.MultipartRequest('POST', Uri.parse(link));
|
||||
request.files.add(
|
||||
http.MultipartFile.fromBytes('image', imagePortrait, filename: '$driverID.jpg'),
|
||||
);
|
||||
|
||||
request.headers.addAll({
|
||||
'Authorization': 'Bearer $token',
|
||||
'X-Device-FP': fingerPrint,
|
||||
});
|
||||
request.fields['driverID'] = box.read(BoxName.driverID).toString();
|
||||
request.headers.addAll({
|
||||
'Authorization': 'Bearer $token',
|
||||
'X-Device-FP': fingerPrint,
|
||||
});
|
||||
request.fields['driverID'] = driverID;
|
||||
|
||||
var response = await request.send();
|
||||
var responseData = await response.stream.toBytes();
|
||||
var responseString = String.fromCharCodes(responseData);
|
||||
final startTime = DateTime.now();
|
||||
var streamedResponse = await client.send(request).timeout(const Duration(seconds: 120));
|
||||
var res = await http.Response.fromStream(streamedResponse);
|
||||
final duration = DateTime.now().difference(startTime);
|
||||
|
||||
Log.print('[UPLOAD_LOGGER] 📥 [uploadImagePortrate] Attempt $attempt response received in ${duration.inSeconds}s. Status Code: ${res.statusCode}');
|
||||
Log.print('[UPLOAD_LOGGER] 📥 [uploadImagePortrate] Response Body: ${res.body}');
|
||||
|
||||
if (res.statusCode == 200) {
|
||||
responseString = res.body;
|
||||
break; // Success
|
||||
} else {
|
||||
throw Exception('Failed to upload portrait: ${res.statusCode} - ${res.body}');
|
||||
}
|
||||
} catch (e, st) {
|
||||
Log.print('[UPLOAD_LOGGER] ⚠️ [uploadImagePortrate] Attempt $attempt failed. Error: $e', stackTrace: st);
|
||||
if (attempt >= maxRetries) {
|
||||
isLoading = false;
|
||||
update();
|
||||
rethrow;
|
||||
}
|
||||
final waitSeconds = attempt * 2;
|
||||
Log.print('[UPLOAD_LOGGER] ⏳ Waiting $waitSeconds seconds before retrying...');
|
||||
await Future.delayed(Duration(seconds: waitSeconds));
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
|
||||
Reference in New Issue
Block a user