Issue
I am trying to send a multipart post request to upload images and sending some other data in flutter with a body looks like this
bodyMap = {
'type' : 'text',
'content': [
{
'type': image'
'identifier: '1234'
}
]
};
However when I'm trying to add it to the request like this
var request = http.MultipartRequest('POST', Uri.parse(url));
request.fields.addAll(bodyMap);
it refuses to add it as it only accepts Map<String, String>
how to solve this problem?
Solution
I have found that Dio Package allows you to post a map of type Map<String,Dynamic> with multipart post request, 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);
Answered By - Ammar Mohamed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.