Future uploadmultipleimage(List<File>img) async {
var uri = Uri.parse("http://192.168.15.106/easy/uploadfile.php");
http.MultipartRequest request = http.MultipartRequest('POST', uri);
//multipartFile = new http.MultipartFile("imagefile", stream, length, filename: basename(imageFile.path));
List<MultipartFile> newList = [];
for (int i = 0; i < img.length; i++) {
File imageFile = File(img[i].path);
var stream =
http.ByteStream(DelegatingStream.typed(imageFile.openRead()));
var length = await imageFile.length();
var multipartFile = http.MultipartFile("file", stream, length,
filename: basename(imageFile.path));
print(imageFile.path);
newList.add(multipartFile);
}
request.files.addAll(newList);
print(newList);
var response = await request.send();
if (response.statusCode == 200) {
print("Image Uploaded");
} else {
print("Upload Failed");
}
response.stream.transform(utf8.decoder).listen((value) {
print(value);
});
}
i have this code which i give it a list of images saved in a List variable from file_picker, i want to upload the list items to the server, but when i run this upload function it only upload the last image not the entire list, i want to know how to upload the entire list of images.
print(newList);
return? – Transcurrentresponse.statusCode
andresponse.reasonPhrase
if that helps? – Transcurrentfile
here:http.MultipartFile("file",
You need a different value for each one, if for no other reason than the server can differentiate file 1, 2, 3, etc. – Wellington