How to send a array in MultipartRequest in flutter?
1,674
Solution 1
'''
request.fields['unit_id[n]'] = "${arrUnitlist[n]}";
or
for(int i = 0; i < arrUnitlist; i++){
request.fields['unit_id[$i]'] = '${arrUnitlist[i]}';
}
'''
works for me
Solution 2
it is possible just open Multipart defination and change final fields = <String,String> to final fields = <String,dynamic> or any other datatype you want.
Solution 3
You can add your array data of unit_id
like this:
var request = new http.MultipartRequest("POST", uri);
request.headers.addAll(headers);
request.fields['property_usage'] = property_use;
request.fields['unit_id[0]'] = "unitlist1";
request.fields['unit_id[1]'] = "unitlist2";
request.fields['unit_id[2]'] = "unitlist3";
var response = await request.send();
![Marzook](https://lh5.googleusercontent.com/-C1-l56z3HaY/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3rf7_b8tFmbhDk4SDW3mHu3ZoT9WsQ/photo.jpg?sz=256)
Comments
-
Marzook over 1 year
this is i am testing my api using postman as array
but how can i send array using MultipartRequest
var uri = Uri.parse(Constants.BASEURL + Constants.KEYEORD_CREATE_TENANACY); Map<String, String> headers = { "Accept": "application/json", "Authorization": token }; var request = new http.MultipartRequest("POST", uri); request.headers.addAll(headers); request.fields['property_usage'] = property_use; request.fields['unit_id'] = unitlist; // here i want unit_id to array var response = await request.send(); print("Tenancy Add Result: ${response.statusCode}"); if (response.statusCode == 200) { print(response); }
-
Taba over 2 yearsDid you got any approach to the issue?
-
-
Marzook almost 4 yearsyes i am sending image to server ! how to solve this issue
-
Elletlar over 3 yearsHi Turaab. Thanks for your answer, but it is not very clear. Can you not provide the code? Kind Regards.