Как мне загрузить изображение со схемой в мое приложение dio flutter
У меня был такой конечный пункт в моем django api
Мне нужно загрузить изображение с деталями поста, чтобы создать один в моем приложении, я трачу дни без какого-либо решения. В flutter я знаю как отправить в схему без другого параметра как изображение, Как новичок в flutter я создаю детали поста в этом коде:
static Future<Account?> add({required String title,required int price,required String det,required String cate,required int w,required int h,required int bed,required int bath,required int location_id}) async {
Response res = await Dio().post(
'http://10.0.2.2:8000/api/post/add-post',
data: jsonEncode(
{
"user_id": Account.currentAcc.id,
"title": title,
"price": price,
"details": det,
"category": cate,
"bedroom": bed,
"bathroom": bath,
"width": w,
"height": h,
"location_post_id": location_id
}
),
);
return null;
}
пожалуйста, помогите мне, если можете :(
)Вам необходимо использовать formdata вместо отправки закодированного json (см. dio docs в разделе Отправка из данных)
Пример для вашего случая:
var formData = FormData.fromMap({
"user_id": Account.currentAcc.id,
"title": title,
"price": price,
"details": det,
"category": cate,
"bedroom": bed,
"bathroom": bath,
"width": w,
"height": h,
"location_post_id": location_id,
'file': await MultipartFile.fromFile('${filePath}',filename: '${fileName}')
});
response = await dio.post('http://10.0.2.2:8000/api/post/add-post', data: formData);