'Unhandled Exception: DioError PONSE]: Http status error [500]
I made FormData use the dio package to upload images to the database, but my compilation was running "flutter run", an error appeared.
After I see the error that appears is a problem with the Http status error [500].
Dio dio = new Dio();
dio.options.headers = {
'Content-type': 'multipart/form-data',
'Accept': 'application/json'
};
FormData formData = new FormData.fromMap({
'name': image_name,
'path': add_path + _uniq[0],
'uuid': _uuid,
'content_type': add_file + image_type,
'file': _image[0],
'record': null
});
Map<String, dynamic> token_send = new Map<String, dynamic>();
token_send = {'token': userGlobal['token']};
response_data = await dio.post(
host + apiVersion + "/formuploads/uploadformattachment",
data: formData,
queryParameters: token_send
);
Then I run it by "flutter run". Then an error appears in the terminal as follows:
E/flutter ( 2970): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: DioError [DioErrorType.RESPONSE]: Http status error [500]
E/flutter ( 2970): #0 DioMixin._dispatchRequest (package:dio/src/dio.dart:943:7)
E/flutter ( 2970): <asynchronous suspension>
E/flutter ( 2970): #1 DioMixin._request._interceptorWrapper.<anonymous closure>.<anonymous
closure>.<anonymous closure> (package:dio/src/dio.dart:828:37)
E/flutter ( 2970): #2 DioMixin.checkIfNeedEnqueue (package:dio/src/dio.dart:1099:22)
E/flutter ( 2970): #3 DioMixin._request._interceptorWrapper.<anonymous closure>.<anonymous
closure> (package:dio/src/dio.dart:825:22)
E/flutter ( 2970): #4 new Future.<anonymous closure> (dart:async/future.dart:176:37)
E/flutter ( 2970): #5 _rootRun (dart:async/zone.dart:1120:38)
E/flutter ( 2970): #6 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 2970): #7 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter ( 2970): #8 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter ( 2970): #9 _rootRun (dart:async/zone.dart:1124:13)
E/flutter ( 2970): #10 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 2970): #11 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
E/flutter ( 2970): #12 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:21:15)
E/flutter ( 2970): #13 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
E/flutter ( 2970): #14 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
E/flutter ( 2970): #15 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Solution 1:[1]
try wrap your file with this method
FormData formData = new FormData.fromMap({
'name': image_name,
'path': add_path + _uniq[0],
'uuid': _uuid,
'content_type': add_file + image_type,
'file': await MultipartFile.fromFile('your file path', 'your file name with extention'),
'record': null
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Amir |