I'm using Dio to upload images to backend. It often gives me the Reference not set
response with a 500
error code. I tried uploading from another source and it seems to be working. What's wrong with this code?
Haven't put the code for performPostRequestWithToken()
because other methods are using it too and it seems to be working alright.
Future<UserModel> submitProfileImage(String imagePath) async {
if (isEmpty(imagePath)) throw Exception("NULL image found");
final formdata = FormData.fromMap({
"profilePic": await MultipartFile.fromFile(
imagePath,
filename: "profilePic.png",
),
});
final usertoken = await getCurrentUserToken();
print(usertoken);
final response = await _dioHttpService.performPostRequestWithToken(
"/User/UploadImage",
formdata,
usertoken,
);
if (response.statusCode >= 200 && response.statusCode < 300) {
return UserModel.fromMap(response.data["data"]);
} else {
throw Exception(response.statusMessage);
}
}
The problem in my case was that the map key
profilePic
was causing the issues. This was definitely a problem from the backend because they were expecting the key to befile
. Changed that and it all worked out.