http
http copied to clipboard
Sending a dynamic value along with multipart request
I am trying to use multipart request to upload images and videos however I want to send a Map<String, Dynamic> but you can only use Map<String, String> which is a big limitation
This is the body I'm trying to send with the request:
bodyMap = {
'type' : 'text',
'content': [
{
'type': image'
'identifier: '1234'
}
]
};
and I try to send it to the request as following:
var request = http.MultipartRequest('POST', Uri.parse(url));
request.fields.addAll(bodyMap);
however it refuses as it only accepts Map<String, String>
Me too, How to fix it?
@SittiphanSittisak I used Dio Package instead it allows you to do use Map<String, Dynamic> for example:
var formData = FormData.fromMap({
'name': 'wendux',
'age': 25,
'file': await MultipartFile.fromFile('./text.txt', filename: 'upload.txt'),
'files': [
await MultipartFile.fromFile('./text1.txt', filename: 'text1.txt'),
await MultipartFile.fromFile('./text2.txt', filename: 'text2.txt'),
]
});
var response = await dio.post('/info', data: formData);
@AmmarMohamed21 Thank you so much. I fix it by json_decode in API.