Files/fields be like :
jsonData,
List[images],
MultipartFile,
sending all these fields/files at once to server using DIO
resolved .. by refering to https://github.com/flutterchina/dio#sending-formdata
Multiple files upload
There are two ways to add multiple files to FormData, the only difference is that upload keys are different for array types。
FormData.fromMap({
"files": [
MultipartFile.fromFileSync("./example/upload.txt",
filename: "upload.txt"),
MultipartFile.fromFileSync("./example/upload.txt",
filename: "upload.txt"),
]
});
The upload key eventually becomes "files[]",This is because many back-end services add a middle bracket to key when they get an array of files. If you don't want “[]”,you should create FormData as follows(Don't use FormData.fromMap):
var formData = FormData();
formData.files.addAll([
MapEntry(
"files",
MultipartFile.fromFileSync("./example/upload.txt",
filename: "upload.txt"),
),
MapEntry(
"files",
MultipartFile.fromFileSync("./example/upload.txt",
filename: "upload.txt"),
),
]);
"files": [
await MultipartFile.fromFile("./text1.txt", filename: "text1.txt"),
await MultipartFile.fromFile("./text2.txt", filename: "text2.txt"),
]
try add [] in "files[]": es:
"files[]": [
await MultipartFile.fromFile("./text1.txt", filename: "text1.txt"),
await MultipartFile.fromFile("./text2.txt", filename: "text2.txt"),
]
From documents of dio:
"Uploading multiple files to server by 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"),
]
});
response = await dio.post("/info", data: formData);
List<MultipartFile> multipartfile is not uploading to server. and when tried multipartfile.elementAt(0) , it's taking .. not understanding what is the problem
dio's official documentation, they show how to do that