I am trying to implement http_interceptor
for refreshing access token on expiry and retry http request. I had searched over internet but I had not found any useful links to work following is my code for multipart request in which I want to implement http_interceptor
.
Future<void> postImage(BuildContext context, String imageType) async {
var data = {"imagetype": imageType, "filename": imageType};
Map<String, String> obj = {"attributes": json.encode(data).toString()};
var flutterFunctions =
Provider.of<FlutterFunctions>(context, listen: false);
final url = Ninecabsapi().urlHost + Ninecabsapi().getvehicle;
try {
loading();
var response = await http.MultipartRequest("POST", Uri.parse(url))
..files.add(await http.MultipartFile.fromPath(
"imagefile", flutterFunctions.imageFile!.path,
contentType: MediaType("image", "jpg")))
..headers['Authorization'] = token!
..fields.addAll(obj);
loading();
notifyListeners();
} catch (e) {
print(e);
}
}
Support for intercepting MultiPartForm data is available in https://pub.dev/packages/http_interceptor/versions/2.0.0-beta.6 Try using it.