uploadImage function
Implementation
Future<bool> uploadImage(String userPhone, File image) async {
try {
BaseOptions options = BaseOptions(
receiveDataWhenStatusError: true,
connectTimeout: const Duration(milliseconds: 5 * 1000), // 60 seconds
receiveTimeout: const Duration(milliseconds: 5 * 1000) // 60 seconds
);
Dio dio = Dio(options);
//todo make structure for package and move http request from here and check exceptions
// (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) {
// client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
// return client;
// };
FormData map = FormData.fromMap({
"file": await MultipartFile.fromFile(image.path, filename: image.path
.split('/')
.last),
"phoneNumber": userPhone
});
final response = await dio.post("${ConstStrings.baseUrl}/api/Images/UploadImage", data: map);
if (response.statusCode == 200) {
debugPrint("signalr_package:successfully upload image");
return true;
} else {
debugPrint("signalr_package: upload image failed response from server gotten");
return false;
}
}catch(exception){
return false;
}
}